Author Topic: managing Keyboard input by _Keyhit and _Keydown  (Read 3811 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
managing Keyboard input by _Keyhit and _Keydown
« on: January 20, 2019, 12:43:33 pm »
Hi guys
Great QB64 that I'm still exploring...
now I'm focusing on the keyboard fast input allowed in QB64

well on my TOSHIBA  Win key (that is on the left part of keyboard) and Menu key ( that is on the right part of keyboard  between Alt Gr and Ctrl at right) give me different codes in respect to those showed into wiki pages for _KEYHIT and _KEYDOWN.

please run this code to see what feedback you have  in your PC!

Code: QB64: [Select]
  1. LOCATE 1, 10: PRINT "Press a key, also Alt, Ctrl, Shift, Keypad... Escape to quit"
  2. LOCATE 2, 2: PRINT "You hit... "
  3. LOCATE 3, 2: PRINT "Left Alt key "
  4. LOCATE 4, 2: PRINT "LeftCtrl key "
  5. LOCATE 5, 2: PRINT "RightCtrl key "
  6. LOCATE 6, 2: PRINT "Alt Grad key"
  7. LOCATE 7, 2: PRINT "Menu key "
  8. LOCATE 8, 2: PRINT "Windows key"
  9. LOCATE 9, 2: PRINT "Windows key"
  10. LOCATE 10, 2: PRINT "RightShift key "
  11. LOCATE 11, 2: PRINT "LeftShift key"
  12.  
  13.     _LIMIT 10  ' WHY QB64 is so fast to need this? :-)
  14.     k = _KEYHIT
  15.     LOCATE 2, 14: PRINT ABS(k); "          "
  16.     LOCATE 2, 30
  17.     IF k < 0 THEN
  18.         PRINT "Key up  "
  19.     ELSEIF k > 0 THEN
  20.         PRINT "Key down "
  21.     ELSE
  22.         PRINT "  no key  " ' no key  and k = 0
  23.     END IF
  24.  
  25.  
  26.     IF _KEYDOWN(100308) THEN 'left alt
  27.         LOCATE 3, 20: PRINT " ON "
  28.     ELSE
  29.         LOCATE 3, 20: PRINT "             "
  30.     END IF
  31.     IF _KEYDOWN(100306) THEN 'left ctrl
  32.         LOCATE 4, 20: PRINT " ON "
  33.     ELSE
  34.         LOCATE 4, 20: PRINT "             "
  35.     END IF
  36.  
  37.     IF _KEYDOWN(100305) THEN 'right ctrl
  38.         LOCATE 5, 20: PRINT " ON "
  39.     ELSE
  40.         LOCATE 5, 20: PRINT "             "
  41.     END IF
  42.     IF _KEYDOWN(100307) THEN 'alt grad
  43.         LOCATE 6, 20: PRINT " ON "
  44.     ELSE
  45.         LOCATE 6, 20: PRINT "             "
  46.     END IF
  47.     IF _KEYDOWN(100319) THEN ' menu key
  48.         LOCATE 7, 20: PRINT " ON "
  49.     ELSE
  50.         LOCATE 7, 20: PRINT "             "
  51.     END IF
  52.     IF _KEYDOWN(100311) THEN 'left win key
  53.         LOCATE 8, 20: PRINT " ON "
  54.     ELSE
  55.         LOCATE 8, 20: PRINT "             "
  56.     END IF
  57.     IF _KEYDOWN(100312) THEN 'right win key
  58.         LOCATE 9, 20: PRINT " ON "
  59.     ELSE
  60.         LOCATE 9, 20: PRINT "             "
  61.     END IF
  62.     IF _KEYDOWN(100303) THEN 'Right Shift key
  63.         LOCATE 10, 20: PRINT " ON "
  64.     ELSE
  65.         LOCATE 10, 20: PRINT "             "
  66.     END IF
  67.     IF _KEYDOWN(100304) THEN 'Left Shift key
  68.         LOCATE 11, 20: PRINT " ON "
  69.     ELSE
  70.         LOCATE 11, 20: PRINT "             "
  71.     END IF
  72.  
  73.  
  74.  
I get 91 for MenuKey and 93 for WinKey...
and you?
Thanks for feedback

PS:
Win10, QB64 1.2 Dev e490b1a
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: managing Keyboard input by _Keyhit and _Keydown
« Reply #1 on: January 20, 2019, 01:17:55 pm »
Left Win key 91
Right Win key 92
Menu key 93 - I had to hook up an external keyboard to my laptop to get that one.

https://www.computerhope.com/jargon/w/winkey.htm (Just to see if we are defining these keys properly. Win key is on the left in the first illustration and the menu key is on the right.

Pete
« Last Edit: January 20, 2019, 01:21:32 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: managing Keyboard input by _Keyhit and _Keydown
« Reply #2 on: January 20, 2019, 06:06:28 pm »
Thanks Pete
you're right

91 for LeftWin Key

93 for Menu Key
I have no Right Win key on my ToSHIBA as you can see https://www.google.it/search?q=toshiba+satellite+c850-1lk&client=opera&hs=idj&source=lnms&tbm=isch&sa=X&ved=0ahUKEwi0nM_Uuf3fAhWSEBQKHTifCgsQ_AUIDygC&biw=1326&bih=665#imgrc=KoP-WMaIxKjX-M:

Following your example I have now used an USB wireless Keyboard and I can get 92 for RightWin key and can confirm  all codes that you have feedback.

Thanks

Now the question is: do we get the same  results in desktop PC?
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: managing Keyboard input by _Keyhit and _Keydown
« Reply #3 on: January 20, 2019, 06:35:13 pm »
91, 92, 93, but it's impossible for me to register a DOWN even. 

Windows 10 traps the key when it goes down, waiting for another keypress so it can do its thing, so QB64 only responds to the key UP event on my machine.

There's no such thing as a down and hold event.  :P

None of the commands work at all for me with _KEYDOWN:

Code: QB64: [Select]
  1.     _LIMIT 60 ' so your PC fan won't explode with an endless loop
  2.     IF _KEYDOWN(91) THEN PRINT "BOO"
  3.     IF _KEYDOWN(92) THEN PRINT "BEES"
  4.     IF _KEYDOWN(93) THEN PRINT "PLEASE"
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: managing Keyboard input by _Keyhit and _Keydown
« Reply #4 on: February 02, 2019, 06:59:24 pm »
Quote
None of the commands work at all for me with _KEYDOWN:
Steve I agree

Code: QB64: [Select]
  1.     _LIMIT 60 ' so your PC fan won't explode with an endless loop
  2.     h& = -(_KEYHIT)
  3.     IF _KEYDOWN(91) THEN PRINT "Boo222"; "       "
  4.     IF h& = 91 THEN PRINT "BOO"; "       "
  5.     IF _KEYDOWN(92) THEN PRINT "BEES222"; "       "
  6.     IF h& = 92 THEN PRINT "BEES"; "       "
  7.     IF _KEYDOWN(93) THEN PRINT "PLEASE222"; "       "
  8.     IF h& = 93 THEN PRINT "PLEASE"; "       "
  9.     IF h& > 0 THEN LOCATE 2, 2: PRINT h&; "       "
  10.  
  11.  
you can manage only Hit events after those of down event of system!
Programming isn't difficult, only it's  consuming time and coffee