GetKey?
BlitzMax Forums/BlitzMax Beginners Area/GetKey?
| ||
I saw that the GetKey() comand is no more... how can I check what keyvalue has been pressed? So far I also used the GetKey() comand to wait until the user pressed any key. I know there is the WaitKey() comand, but I usually want to exit a loop. Repeat Until GetKey() <> 0 How can I do this in BMax?? |
| ||
This is from the html manual:KeyHit( keycode ) Check for key hit Returns: Number of times key has been hit. KeyHit also resets the count for the key specified to zero. See the KeyCodes docs for a list of valid keycodes. Example: ' keyhit.bmx ' the following code draws a circle every time the ' program detects the spacebar has been pressed ' and exits when it detects the ESCAPE key has ' been pressed Graphics 640,480 While Not KeyHit(KEY_ESCAPE) Cls If KeyHit(KEY_SPACE) DrawOval 0,0,640,480 Flip Wend Barney |
| ||
Well, yes.. but this does not explain, how I can get the value of a unknown key that has been pressed by the user, it returns the number of times a KNOWN key has been hit. |
| ||
There's no equivalent right now. Will have to be a feature request, I guess! |
| ||
I was trying to think how to do this also but I don't think there's a token as yet. However, you can use the preset identifiers to check for a specific key ie If KeyHit(KEY_ESCAPE) Then End Sooooooo... obviously KEY_ESCAPE has some kind of mask bits or numerical value that gets compared to the key code of the key that's been hit... SO I wonder.... Is there a mask you can submit like $FFFF or something, that will return true if ANY key has been hit? That'd be at least half of the problem solved (if it even works) ... but I don't know how you could just get a raw key code and play with it. |
| ||
You could just test KeyHit for keycode=0 to keycode=255. Looking at the system.mod source, it seems that every time a key is hit, Blitz increments one of the slots in a 255-byte array. KeyHit just retrieves key_hit[keycode], so a check for all 255 keys would be very fast. Edit: Looking at the MacOS .m code for system, it seems that a fixed lookup table to convert from virtual key codes to ASCII values - isn't this going to cause a problem for non NZ-layout keyboards? |
| ||
There's no equivalent right now. Will have to be a feature request, I guess! Please put it HIGH on the list. :) This is sort of important for people typing in their names for high score lists and things like that... |
| ||
This is almost similar to the B3D/B+ variant. With a bit of extra typing you can get it to return Ascii values instead of scancodes...Function GetKey() Repeat For Local n=1 To 255 If KeyHit(n) Return n Next Forever End FunctionOr perhaps it's better to add it to the system.xxx.bmx mods? Something along these lines: Method GetKey( ) For Local keycode = 1 to 255 Local n=bbSystemKeyHit[keycode] if n return n Next End MethodDon't know if it'll work... |