Page 1 of 1
Scripting - user keyboard input
Posted: Mon Oct 09, 2017 12:30 am
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"?
Re: Scripting - user keyboard input
Posted: Mon Oct 09, 2017 1:46 am
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.
Re: Scripting - user keyboard input
Posted: Mon Oct 09, 2017 2:02 pm
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)?
Re: Scripting - user keyboard input
Posted: Tue Oct 10, 2017 1:15 am
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
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?
Re: Scripting - user keyboard input
Posted: Tue Oct 10, 2017 3:12 am
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.