Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: Rodo on December 21, 2010, 07:35:30 pm

Title: keypressed
Post 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.
Title: Re: keypressed
Post by: Droid803 on December 22, 2010, 01:06:17 am
The Zoom script uses it IIRC.

EDIT: nope, it uses $On Key Pressed, never mind.
Title: Re: keypressed
Post by: m!m on December 22, 2010, 02:36:54 am
You could still use $On Key Pressed and set a global variable to get your information.
Title: Re: keypressed
Post by: Rodo on December 22, 2010, 10:56:23 am
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?
Title: Re: keypressed
Post by: m!m on December 22, 2010, 12:36:28 pm
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
Code: [Select]
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.
Title: Re: keypressed
Post by: Rodo on December 22, 2010, 12:43:45 pm
Yeah I tried using your method with hv.Key:lower() , but I guess I used it in incorrectly.

Will try again later today, thanks!