Scripts / How To Check Key Press

Author
Message
Nevin
9
Years of Service
User Offline
Joined: 19th May 2015
Location: U.S.A
Posted: 24th Oct 2016 18:09
How to check if player presses a key?

If player presses 'L', how would I check this?

I tried g_InKey = "" and GetInKey

But I would like a small example to work off of. They don't seem to work for me.

For a start, I tried if g_InKey == "L" as a test, but it did not work. So i'm kinda lost why it could not find it.
gd
8
Years of Service
User Offline
Joined: 21st Jul 2016
Location: Small Darkroom with no red light
Posted: 24th Oct 2016 19:26 Edited at: 24th Oct 2016 19:46
Hi Nevin, you could use g_Scancode instead of g_InKey=="o"



You can also add the line of code below to you lua script for testing, then just comment it out or delete once tested.



The scan key code for "L" will be 38. Keep in mind also that the next key Scancode's is just the last plus 1 in a row on the keyboard 9 times of of 10.

An example of your code would be good to post here as this is hard to gauge with out it.
How many time is it run?
Is the code in a loop for it to be seen?
What happens once its found?
Are you using flags once its found?

With g_Scancode you also need to scan for if no key is pressed i.e. g_Scancode==0 which you would use a flag for it. The next example is to show or hide huds.

Example:

Dark Base 900 Pro OJ: Rampage V Ed.10, i7 6950x non-OC, DDR4-3333 64 GB RAM, Win 10/64, Asus Strix GeForce 1080 x 2 MDA mode, Water cooled with an old Victorian cast iron radiator and a industrial leather belt driven fan - That's what you call Steampunked.

Laptop - M17xR3
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 24th Oct 2016 19:35
it likely didn't work because g_Inkey is case/capital specific, use g_Scancode to check for both versions of the letter at once (i.e. l & L)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
gd
8
Years of Service
User Offline
Joined: 21st Jul 2016
Location: Small Darkroom with no red light
Posted: 24th Oct 2016 19:55 Edited at: 24th Oct 2016 19:56
Hi, Belidos added this keyboard map of scan codes. I hope it helps.

Dark Base 900 Pro OJ: Rampage V Ed.10, i7 6950x non-OC, DDR4-3333 64 GB RAM, Win 10/64, Asus Strix GeForce 1080 x 2 MDA mode, Water cooled with an old Victorian cast iron radiator and a industrial leather belt driven fan - That's what you call Steampunked.

Laptop - M17xR3
PM

Login to post a reply

Server time is: 2024-12-22 23:10:49
Your offset time is: 2024-12-22 23:10:49