Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
_BUTTON
#1
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.p...er_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
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#2
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||                                                                                              |
'                                  ||___|||___|||___||                                                                                              |
'                                  |/___\|/___\|/___\|                                                                                              |
'                                                                                                                                                   |
'\__________________________________________________________________________________________________________________________________________________/
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#3
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?
Reply
#4
(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.)
Reply
#5
(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.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#6
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.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#7
I've just updated the https://qb64phoenix.com/qb64wiki/index.p...er_Devices page with the most recent info I could find in the old wikis, could you check if the values match now Huh
Reply
#8
(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.
Reply
#9
(04-03-2023, 10:03 PM)RhoSigma Wrote: I've just updated the https://qb64phoenix.com/qb64wiki/index.p...er_Devices page with the most recent info I could find in the old wikis, could you check if the values match now Huh

Yes, I looked each one over and the values are the same as what I found. Thank you for updating that chart.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply
#10
(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.
There are two ways to write error-free programs; only the third one works.
QB64 Tutorial
Reply




Users browsing this thread: 1 Guest(s)