Keydown() Exercise
BlitzMax Forums/BlitzMax Beginners Area/Keydown() Exercise
| ||
The code...Graphics 640,480 While Not KeyDown(KEY_ESCAPE) If KeyDown(KEY_NUM8) Then UPDOWN_NUM Wend Function UPDOWN_NUM() If KeyDown(KEY_LSHIFT) Or KeyDown(KEY_RSHIFT) Then DebugLog "Shifted" Else DebugLog "UN-SHIFTED" EndIf End Function ...doesn't work. Is there something special about using the NUM keys that disable the shift keys? |
| ||
the KEY_NUM8 should be in the keypad try KEY_8 instead |
| ||
Yes...NUM8 is in the keypad. I want to use it. Why doesn't the detection for a shift key work? |
| ||
Does the DEBUGLOG work? I exchanged DEBUGLOG with PRINT. And I exchanged KEY_NUM8 with KEY_8. It seems to exist no combination of NUM-Keys an SHIFT: This sample runs perfect on my machine: Global Zeit%, Time% Graphics 640,480 time=MilliSecs() While Not KeyDown(KEY_ESCAPE) If KeyDown(KEY_NUM8) Then UPDOWN_NUM "NUM 8" If KeyDown(KEY_8) Then UPDOWN_NUM "KEY 8" If zeit<MilliSecs() If KeyDown(KEY_LSHIFT) Or KeyDown(KEY_RSHIFT) Then Print "Only Shifted" Else Print Int(MilliSecs()-time)/100 EndIf zeit=MilliSecs()+100 EndIf Wend Function UPDOWN_NUM(FirstKey$) If zeit<MilliSecs() If KeyDown(KEY_LSHIFT) Or KeyDown(KEY_RSHIFT) Then Print FirstKey + "Shifted" Else Print FirstKey + " UN-SHIFTED" EndIf zeit=MilliSecs()+100 EndIf End Function |
| ||
@Midimaster The KeyDown command is used to detect whether a key is pressed or not...regardless of what other key is used. So if I press a shift key, I should be able to detect it. The example you provide does not work...it does almost the same thing as my example. I do not want '8', I need 'NUM8'. |
| ||
Most Keyboards can only detect a very limited ammount of keypresses, and it *may* be that the NUM-Keys an the shift Keys are on the same Data structures of the keyboards Hardware. If this is the case (which makes sense to me as there are no 'shift pressed symbols' on those keys as they normally only get used for number input) you can't do anything to change this behaviour. |
| ||
is this windows only? http://www.blitzbasic.com/Community/posts.php?topic=71454#798973 there are some bugs in windows input... hah, i will open this case again.. :D and check is there something wrong.... Last edited 2012 |
| ||
also check this:SuperStrict Graphics 600,300 Global L:Int,R:Int Rem WINDOWS BUGS: LEFT SHIFT DOWN and then RIGHT CONTROL down. RELEASE right control. and => you will get both left and right control KEY UP EVENTS.. or RIGHT SHIFT DOWN and then LEFT CONTROL down. and RELEASE CONTROL.. and =>2 LEFT CONTROL "KEY_UP" EVENTS" :O NOTE: Check Console Output window. EndRem While Not KeyHit(key_escape) Cls 'DrawText "LEFT="+KeyDown(KEY_LSHIFT),0,0 'DrawText "RIGH="+KeyDown(KEY_RSHIFT),100,0 Local event:Int=PollEvent() If event Select EventID() Case EVENT_KEYDOWN Local data:Int=EventData() Print "down="+data Select data Case KEY_LSHIFT L=1 Case KEY_RSHIFT R=1 End Select Case EVENT_KEYUP Local data:Int=EventData() Print "UP="+data Select data Case KEY_LSHIFT L=0 Case KEY_RSHIFT R=0 End Select End Select EndIf DrawText "L="+L,0,40 DrawText "R="+R,100,40 Flip Wend |
| ||
I don't think using the keypad for key input is a good idea if you are making a game or for general purpose applications. I don't know what the ration of laptops to desktops is but I am sure the laptop ration is pretty high, and how many PC users have a laptop that have a keypad? But, if you insist on using the keypad and you might have your reasons, why don't you use GetChar? Last edited 2012 |
| ||
@pc_tec yes... this is exactly, what I want to tell you: It does not work! But it is not a bug in the code, it is a disability of the keyboard! |
| ||
Thanks to all for the information. I will redo the code to other keys. (at some point). Cheers again! |