GetKey() Help.

Blitz3D Forums/Blitz3D Programming/GetKey() Help.

Black Hydra(Posted 2005) [#1]
Sounded simple enough.

I wanted to make a key-remap feature for my game. Gamasutra even noted it as a "Twinkie Denial Condition", meaning that it was a big no-no for today's games not to include a key-remap. Well, at least for games that use more than the mouse and maybe a button.

Anyways, I managed to use GetKey in order to grab all of those ASCII characters on the keyboard for remapping. It grabs them fine, and I use manual trapping using KeyDown() to grab all the other non-important keys such as Shift, Ctrl , Alt and the likes.

Unfortunately, in my game, GetKey isn't giving me anything. Not when I hold the key, and not when I tap it. Nothing, ever.

I made this line of code into my editor to make sure it wasn't some coding bug of my remapping options:

DebugLog Chr(GetKey())

No luck, it simply is making new lines constantly in the debug log.

I used this code to see if the correct key was hit. I'm simplifying it as the actual variables differ.



Is GetKey somehow restrictive on time. If it is I am really going to have to think, as I don't want to have to individually make a comparison chart for every keyboard character to each scancode.


WolRon(Posted 2005) [#2]
GetKey() stops code execution, and (if I'm not mistaken) also can only be used in 'console' mode (may need to double-check that).

EDIT: Oops, I think I stirred that up from back in the SmartBASIC days...


Black Hydra(Posted 2005) [#3]
Nope, that's WaitKey.

The snippet for GetKey is:

While Not value
value = GetKey
Wend

Print "You clicked ASCII character: "+value

besides. If it had stopped execution I would have known about that as it would have screwed up much of my other code.

I'm just unsure if there is some sort of glitch with GetKey() that doesn't allow me to get a positive keyhitting result like KeyHit() or KeyDown()?

If there was a Scan() function that took an ASCII character and returned a scancode this would be soooo much easier.


jfk EO-11110(Posted 2005) [#4]
you meant input.

As far as I know, getkey() should work nicely, tho it delivers the ascii codes that are language specific, unlike the scancodes given by KeyHit()/Keydown()

Unfortunately there is no built in lookup table to see what scancode is what ascii char.

you have to store the value of getkey() (brackets required!) in a variable, so you can reuse it, cause if you use it twice, the second time it's gonna be emty (it will be flushed by reading it)

The easiest way is to allow the user to remap it manually, and when he presses a key, you can automaticly read its ascii value and display it correctly if you want. There may be a problem as long as you don't know them in the first place.

Maybe it's possible to get the scancode/ascii lookup table using some windows Api calls.


Black Hydra(Posted 2005) [#5]
No, WaitKey returns the ASCII character value just like GetKey(), it just halts execution while it does so. Just look at the help file for WaitKey.

My problem is probably that the GetKey is flushing all values. Now I'm really going to have to think. How can I have it check whether your holding a key if getkey only works like KeyHit()!?!

I could work around the flushing of the getkey by storing it in a variable each loop, but some of my items work by holding them down constantly. This won't work if I use GetKey()?

I'm thinking I might just have to make a complete scancode chart for all mappable keys. This is ridiculous, Blitz really needs either a ScanHit/Down() function.