Hard Light Productions Forums
Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: Rodo on December 21, 2010, 07:35:30 pm
-
The isKeyPressed function seems to be disabled in lua.cpp, is there another way to get that data? I mean if a certain key is pressed ingame.
I tried looking in some of the example scripts but i've been out of luck so far.
-
The Zoom script uses it IIRC.
EDIT: nope, it uses $On Key Pressed, never mind.
-
You could still use $On Key Pressed and set a global variable to get your information.
-
I tried copying the zoom script but I can't find the way to capture the key, I think I'm missing the way the $On Key Pressed works, should I declare a global variable and then what?
From what I can understand from reading the scripting entries on the wiki, that conditional hook will run every time ANY key is pressed... or am I mistaken and it actually checks which key was pressed?
-
If you want to know the current key at any time you can save the pressed key from $On Key Pressed in a global variable and reset it in $On Key Released.
If you want to know whether a specific key is pressed just use if hv.Key:lower() == "<key here>" then ...
and set a global boolean if the pressed key matches your key.
Or you can use the $KeyPress condition and set your wanted key there.
From what I read I would suggest using the third approach as it's the easiest.
-
Yeah I tried using your method with hv.Key:lower() , but I guess I used it in incorrectly.
Will try again later today, thanks!