Scripting - user keyboard input

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
BeNNyBiLL
Posts: 40
Joined: Mon Oct 08, 2012 11:00 pm

Scripting - user keyboard input

Post by BeNNyBiLL »

Hello. It's been a long time since I've done any Grimrock modding and I was hoping someone could help me with a few things I can't find an answer for (although I fear the answer is going to be, "no I can't!")

Is there a way to handle custom user input (i.e. keyboard commands)? Example usage could be detecting if the SHIFT key is down to make the party sprint.

Also can you enforce game modes like "Ironman" and "Single use crystals"?
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Scripting - user keyboard input

Post by minmay »

Yes, you can use keyboard input. The GraphicsContext class has a keyDown() function that tells you whether a key is currently pressed, although it doesn't work for every key.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
BeNNyBiLL
Posts: 40
Joined: Mon Oct 08, 2012 11:00 pm

Re: Scripting - user keyboard input

Post by BeNNyBiLL »

Thanks for the reply minmay.

I saw the GraphicsContext in the scripting reference and assumed it was just for handling GUI. I'll be sure to try it. How do I access the GraphicsContext in script? Is there an example of its usage anywhere? Is there a list of valid keys/ids on this forum that can be passed into the keyDown() func?

I don't suppose there is a way of detecting onKeyDown()?

I also spotted this in the reference: Config.getKeyBinding(action)
Seems a bit strange to me that this exists without a Config.setKeyBinding(key, action)?
BeNNyBiLL
Posts: 40
Joined: Mon Oct 08, 2012 11:00 pm

Re: Scripting - user keyboard input

Post by BeNNyBiLL »

OK I have worked out the bare essentials for this. I'm on my way now, I can just record keyUps and keyDowns. Piece of cake :D

Code: Select all

onDrawGui = function(self, context)
    print(context.keyDown("shift"))
end
Can anyone confirm if its possible to enforce game modes like "Ironman" and "Single use crystals", other than asking the user nicely in the description to use such settings?
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Scripting - user keyboard input

Post by minmay »

It is not. (Not really sure why you'd want to, either.) If you want to make a single-use crystal, you can always give it a cooldown of math.huge.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply