_BUTTON - TerryRitchie - 04-03-2023
I'm looking to write an input driver for the project I'm working on. _BUTTON and the various related functions seems to be what I'm looking for. However, the table for the keyboard device button numbers, found here in the wiki: https://qb64phoenix.com/qb64wiki/index.php/Controller_Devices
does not match the output when I run the example code found on the same page. The keyboard numbers I'm getting are completely different from the chart. Why is this?
Code: (Select All) PRINT "Use relative mouse movement mode with ESC key exit only?(Y/N) ";
K$ = UCASE$(INPUT$(1))
PRINT K$
PRINT
FOR i = 1 TO _DEVICES 'DEVICES MUST be read first!
PRINT STR$(i) + ") " + _DEVICE$(i) + " Buttons:"; _LASTBUTTON(i); ",Axis:"; _LASTAXIS(i); ",Wheel:"; _LASTWHEEL(i)
NEXT
IF K$ = "Y" THEN dummy = _MOUSEMOVEMENTX 'enable relative mouse movement reads
PRINT
DO
x& = _DEVICEINPUT 'determines which device is currently being used
IF x& = 1 THEN
PRINT "Keyboard: ";
FOR b = 1 TO _LASTBUTTON(x&)
bb = _BUTTONCHANGE(b)
IF bb THEN PRINT b; bb; _BUTTON(b);
NEXT
PRINT
END IF
IF x& > 1 THEN ' skip keyboard reads
PRINT "Device:"; x&;
FOR b = 1 TO _LASTBUTTON(x&)
PRINT _BUTTONCHANGE(b); _BUTTON(b);
NEXT
FOR a = 1 TO _LASTAXIS(x&)
PRINT _AXIS(a); 'mouse axis returns -1 to 1 with 0 center screen
NEXT
FOR w = 1 TO _LASTWHEEL(x&)
PRINT _WHEEL(w); 'wheels 1 and 2 of mouse return relative pixel moves when enabled
NEXT
PRINT
END IF
LOOP UNTIL INKEY$ = CHR$(27) 'escape key exit
END
RE: _BUTTON - TerryRitchie - 04-03-2023
I found a library called:
' GX - A BASIC Game Engine for QB64
' 2021 boxgaming - https://github.com/boxgaming/gx
that had mapped all the _BUTTON vales to keys in a file called gx.bi. I used that as a basis to create the code below if anyone needs the _BUTTON values for the keyboard.
Code: (Select All) ' __________________________________________________________________________________________________________________________________________________
'/ KEYBOARD KEY _BUTTON CONSTANTS \
CONST GLKEY_ESC = 2 ' |
CONST GLKEY_F1 = 60 ' FUNCTION KEY ROW _BUTTON CONSTANTS |
CONST GLKEY_F2 = 61 ' _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ |
CONST GLKEY_F3 = 62 ' ||ESC|| ||F1 |||F2 |||F3 |||F4 || ||F5 |||F6 |||F7 |||F8 || ||F9 |||N/A|||F11|||F12|| |
CONST GLKEY_F4 = 63 ' ||___|| ||___|||___|||___|||___|| ||___|||___|||___|||___|| ||___|||___|||___|||___|| |
CONST GLKEY_F5 = 64 ' |/___\| |/___\|/___\|/___\|/___\| |/___\|/___\|/___\|/___\| |/___\|/___\|/___\|/___\| |
CONST GLKEY_F6 = 65 ' |
CONST GLKEY_F7 = 66 ' NOTE: F10 does not register as a _BUTTON. I know, strange but true. |
CONST GLKEY_F8 = 67 ' |
CONST GLKEY_F9 = 68 ' |
CONST GLKEY_F11 = 88 ' |
CONST GLKEY_F12 = 89 ' |
CONST GLKEY_BACKQUOTE = 42 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_1 = 3 ' FIRST KEY ROW _BUTTON CONSTANTS |
CONST GLKEY_2 = 4 ' |
CONST GLKEY_3 = 5 ' _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _________ |
CONST GLKEY_4 = 6 ' ||`~ |||1! |||2@ |||3# |||4$ |||5% |||6^ |||7& |||8* |||9( |||0) |||-_ |||=+ |||BACKSP || |
CONST GLKEY_5 = 7 ' ||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||_______|| |
CONST GLKEY_6 = 8 ' |/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/_______\| |
CONST GLKEY_7 = 9 ' |
CONST GLKEY_8 = 10 ' |
CONST GLKEY_9 = 11 ' |
CONST GLKEY_0 = 12 ' |
CONST GLKEY_MINUS = 13 ' |
CONST GLKEY_EQUALS = 14 ' |
CONST GLKEY_BACKSPACE = 15 ' |
CONST GLKEY_TAB = 16 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_Q = 17 ' SECOND KEY ROW _BUTTON CONSTANTS |
CONST GLKEY_W = 18 ' |
CONST GLKEY_E = 19 ' _______ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _______ |
CONST GLKEY_R = 20 ' ||TAB |||Q |||W |||E |||R |||T |||Y |||U |||I |||O |||P |||[{ |||]} |||\| || |
CONST GLKEY_T = 21 ' ||_____|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||_____|| |
CONST GLKEY_Y = 22 ' |/_____\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/_____\| |
CONST GLKEY_U = 23 ' |
CONST GLKEY_I = 24 ' |
CONST GLKEY_O = 25 ' |
CONST GLKEY_P = 26 ' |
CONST GLKEY_LBRACKET = 27 ' |
CONST GLKEY_RBRACKET = 28 ' |
CONST GLKEY_BACKSLASH = 44 ' |
CONST GLKEY_CAPSLOCK = 59 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_A = 31 ' THIRD KEY ROW _BUTTON CONSTANTS |
CONST GLKEY_S = 32 ' |
CONST GLKEY_D = 33 ' ________ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ ____________ |
CONST GLKEY_F = 34 ' ||CAPS |||A |||S |||D |||F |||G |||H |||J |||K |||L |||;: |||'" |||ENTER || |
CONST GLKEY_G = 35 ' ||______|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||__________|| |
CONST GLKEY_H = 36 ' |/______\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/__________\| |
CONST GLKEY_J = 37 ' |
CONST GLKEY_K = 38 ' |
CONST GLKEY_L = 39 ' |
CONST GLKEY_SEMICOLON = 40 ' |
CONST GLKEY_QUOTE = 41 ' |
CONST GLKEY_ENTER = 29 ' |
CONST GLKEY_LSHIFT = 43 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_Z = 45 ' FOURTH KEY ROW _BUTTON CONSTANTS |
CONST GLKEY_X = 46 ' |
CONST GLKEY_C = 47 ' _____________ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____ _____________ |
CONST GLKEY_V = 48 ' ||LEFT SHIFT |||Z |||X |||C |||V |||B |||N |||M |||,< |||.> |||/? |||RIGHT SHIFT|| |
CONST GLKEY_B = 49 ' ||___________|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___|||___________|| |
CONST GLKEY_N = 50 ' |/___________\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___\|/___________\| |
CONST GLKEY_M = 51 ' |
CONST GLKEY_COMMA = 52 ' |
CONST GLKEY_PERIOD = 53 ' |
CONST GLKEY_SLASH = 54 ' |
CONST GLKEY_RSHIFT = 55 ' |
CONST GLKEY_LCTRL = 30 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_LWIN = 348 ' FIFTH KEY ROW _BUTTON CONSTANTS |
CONST GLKEY_SPACEBAR = 58 ' |
CONST GLKEY_RWIN = 349 ' ______ ______ ______ _____________________________________________ ______ ______ ______ |
CONST GLKEY_RCTRL = 286 ' ||LCTL|||LWIN|||MENU|||SPACEBAR |||N/A |||RWIN|||RCTL|| |
CONST GLKEY_MENU = 350 ' ||____|||____|||____|||___________________________________________|||____|||____|||____|| |
' |/____\|/____\|/____\|/___________________________________________\|/____\|/____\|/____\| |
' |
CONST GLKEY_NUMLOCK = 326 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_NUMPAD_DIVIDE = 310 ' NUMBER PAD _BUTTON CONSTANTS |
CONST GLKEY_NUMPAD_MULTIPLY = 56 ' |
CONST GLKEY_NUMPAD_MINUS = 75 ' _____ _____ _____ _____ |
CONST GLKEY_NUMPAD_7 = 72 ' ||NUM|||/ |||* |||- || |
CONST GLKEY_NUMPAD_8 = 73 ' ||___|||___|||___|||___|| |
CONST GLKEY_NUMPAD_9 = 74 ' |/___\|/___\|/___\|/___\| |
CONST GLKEY_NUMPAD_PLUS = 79 ' _____ _____ _____ _____ |
CONST GLKEY_NUMPAD_4 = 76 ' ||7 |||8 |||9 |||+ || |
CONST GLKEY_NUMPAD_5 = 77 ' ||___|||___|||___||| || |
CONST GLKEY_NUMPAD_6 = 78 ' |/___\|/___\|/___\|| || |
CONST GLKEY_NUMPAD_1 = 80 ' _____ _____ _____|| || |
CONST GLKEY_NUMPAD_2 = 81 ' ||4 |||5 |||6 ||| || |
CONST GLKEY_NUMPAD_3 = 82 ' ||___|||___|||___|||___|| |
CONST GLKEY_NUMPAD_ENTER = 285 ' |/___\|/___\|/___\|/___\| |
CONST GLKEY_NUMPAD_0 = 83 ' _____ _____ _____ _____ |
CONST GLKEY_NUMPAD_PERIOD = 84 ' ||1 |||2 |||3 |||E || |
' ||___|||___|||___|||N || |
' |/___\|/___\|/___\||T || |
' ___________ _____||E || |
' ||0 |||. |||R || |
' ||_________|||___|||___|| |
' |/_________\|/___\|/___\| |
' |
CONST GLKEY_UP = 329 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_LEFT = 332 ' ARROW KEY _BUTTON CONSTANTS |
CONST GLKEY_DOWN = 337 ' |
CONST GLKEY_RIGHT = 334 ' _____ |
' || ^ || |
' ||___|| |
' |/___\| |
' _____ _____ _____ |
' || < ||| V ||| > || |
' ||___|||___|||___|| |
' |/___\|/___\|/___\| |
' |
CONST GLKEY_SCRLK = 71 ' ----------------------------------------------------------------------------------------- |
CONST GLKEY_PAUSE = 70 ' POSITION KEY _BUTTON CONSTANTS |
CONST GLKEY_INSERT = 339 ' |
CONST GLKEY_HOME = 328 ' _____ _____ _____ |
CONST GLKEY_PAGEUP = 330 ' ||N/A|||SCR|||PAU|| |
CONST GLKEY_DELETE = 340 ' ||___|||___|||___|| |
CONST GLKEY_END = 336 ' |/___\|/___\|/___\| |
CONST GLKEY_PAGEDOWN = 338 ' _____ _____ _____| |
' ||INS|||HOM|||PUP|| |
' ||___|||___|||___|| |
' |/___\|/___\|/___\| |
' _____ _____ _____ |
' ||DEL|||END|||PDN|| |
' ||___|||___|||___|| |
' |/___\|/___\|/___\| |
' |
'\__________________________________________________________________________________________________________________________________________________/
RE: _BUTTON - SMcNeill - 04-03-2023
From what I recall, QB64's button values are currently the same as the console/CINP/INP values.
https://qb64phoenix.com/qb64wiki/index.php/Scancodes -- are those not the values you get?
RE: _BUTTON - SMcNeill - 04-03-2023
(The page you referenced, I think, refers back to the ooooold SDL codes for _DEVICES. It's drastically out of date, if I'm right.)
RE: _BUTTON - TerryRitchie - 04-03-2023
(04-03-2023, 09:03 PM)SMcNeill Wrote: From what I recall, QB64's button values are currently the same as the console/CINP/INP values.
https://qb64phoenix.com/qb64wiki/index.php/Scancodes -- are those not the values you get?
No, some of the codes match but many do not.
RE: _BUTTON - TerryRitchie - 04-03-2023
I just went through every key to double check the values I have are returned by _BUTTON.
They all match the code I posted above.
However, the PAUSE key is not being registered? In the code I found it's listed as a value of 70 but I get nothing when pressed.
Oh, and my keyboard does not have a Windows Menu button so I was unable to test that one.
RE: _BUTTON - RhoSigma - 04-03-2023
I've just updated the https://qb64phoenix.com/qb64wiki/index.php/Controller_Devices page with the most recent info I could find in the old wikis, could you check if the values match now
RE: _BUTTON - dbox - 04-03-2023
(04-03-2023, 08:40 PM)TerryRitchie Wrote: I found a library called:
' GX - A BASIC Game Engine for QB64
' 2021 boxgaming - https://github.com/boxgaming/gx
that had mapped all the _BUTTON vales to keys in a file called gx.bi. I used that as a basis to create the code below if anyone needs the _BUTTON values for the keyboard.
Yes, that was an interesting exercise. I wanted to have generic and consistent device detection and input mapping across different types of game device inputs (gamepad, keyboard, mouse) using _DEVICEINPUT. I also found that _DEVICEINPUT didn't work for keyboard button state on macos so GX has a fallback for that OS to use _keydown.
RE: _BUTTON - TerryRitchie - 04-04-2023
(04-03-2023, 10:03 PM)RhoSigma Wrote: I've just updated the https://qb64phoenix.com/qb64wiki/index.php/Controller_Devices page with the most recent info I could find in the old wikis, could you check if the values match now
Yes, I looked each one over and the values are the same as what I found. Thank you for updating that chart.
RE: _BUTTON - TerryRitchie - 04-04-2023
(04-03-2023, 11:07 PM)dbox Wrote: (04-03-2023, 08:40 PM)TerryRitchie Wrote: I found a library called:
' GX - A BASIC Game Engine for QB64
' 2021 boxgaming - https://github.com/boxgaming/gx
that had mapped all the _BUTTON vales to keys in a file called gx.bi. I used that as a basis to create the code below if anyone needs the _BUTTON values for the keyboard.
Yes, that was an interesting exercise. I wanted to have generic and consistent device detection and input mapping across different types of game device inputs (gamepad, keyboard, mouse) using _DEVICEINPUT. I also found that _DEVICEINPUT didn't work for keyboard button state on macos so GX has a fallback for that OS to use _keydown.
That information was very helpful. Thank you.
|