Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Just a little help with Scancode...

Author
Message
Lonnehart
15
Years of Service
User Offline
Joined: 17th Apr 2009
Location:
Posted: 18th May 2011 02:49
I'm experimenting at the moment with scancode. I want to be able to give the player the option of choosing his own control scheme with the keyboard rather than be restricted to the WASD keys. Well... here it is...



For now what I want to do is to use the scancode to get the actual key that was pressed, and print it out with its scancode (for example, if you pressed the letter "W", it would print out the scancode first, then the letter by reading the scancode)...

Okay... my brain's smoking again.

Dar13
16
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 18th May 2011 03:16
I had the same situation when I was making an options menu for my project. What I ended up doing was making a set of constants that had the scancodes of the keys I expected the player to use plus some, and then got the scancode and passed it into this function:


I know it's not the cleanest or most beautiful code, but it works. Maybe someone can come and show us both a better way to do it?


Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 18th May 2011 11:30 Edited at: 18th May 2011 11:34
hmmm, Try this code,



Its a quick job and i'm sure there's a better way of doing it, but this worked for me. dunno how to fake the key press though...

hope this helps
kezzla

Sometimes I like to use words out of contents
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th May 2011 12:59 Edited at: 18th May 2011 13:01
Looks like you have some ideas for this but how about putting your keys into a UDT. This way you just have to change the value of the scancode key in the UDT and every time you call a check on that key you use the same simple code:

scancode() has its uses but keystate() will allow you to use multiple keypresses too.

Login to post a reply

Server time is: 2024-11-16 21:55:59
Your offset time is: 2024-11-16 21:55:59