Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Html5 doesn't support numeric keypad?

Author
Message
Prime
User Offline
Joined: 15th Jun 2022
Location:
Posted: 23rd Jul 2022 22:18
I'm having trouble using the numeric keypad on my keyboard to input numbers in the html5 version of my app. The numbers on the top row work fine, and both sets of numeric keys work when I launch the app in windows.

Is this a known issue, is it just me, or is there a workaround?
Virtual Nomad
Moderator
16
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Jul 2022 22:43 Edited at: 23rd Jul 2022 22:48
i just discovered this myself ~ a month ago.

my post on discord: "interesting... it seems NumPad is the same as the ArrowKeys in HTML ScanCode-wise...".

i received no response to that but it appears they're the same as the arrowkeys (ie, 37-40) which corresponds to numpad 4,8,6 & 2 but don't recall what the others may have returned. (should be Home, End, Page Up/Down, insert, delete, etc.)

further testing should utilize GetRawLastKey() to see what the others might correspond to. if i get a chance, i'll put something together and report.

then, i believe it was raven who suggested using GetCharBuffer() for something related (distinguishing Upper/Lower keypresses) so i'll take a look at that, too, unless you/someone else beats me to it.
Virtual Nomad
Moderator
16
Years of Service
Recently Online
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 23rd Jul 2022 23:50 Edited at: 24th Jul 2022 00:18
ok, taking a further look
Quote: "it appears they're the same as the arrowkeys"

...seems to apply when Shift is held down ON DESKTOP.

otherwise, see the HTML player source and this HTML Scancode tool for AGK (my manual testing results match the source).

don't ask my why it is this way but it's not good for the numeric entry you're looking for

you could map the keys to corresponding numbers, tho, and since there are so few, it wouldn't be much of a chore BUT there would be no way (that i know of) to determine whether or not the user pressed NumPad 4 OR LeftKey, for example, so those corresponding keys outside of the NumPad would be pretty useless.
Prime
User Offline
Joined: 15th Jun 2022
Location:
Posted: 24th Jul 2022 00:59
Quote: "you could map the keys to corresponding numbers, tho, and since there are so few, it wouldn't be much of a chore BUT there would be no way (that i know of) to determine whether or not the user pressed NumPad 4 OR LeftKey, for example, so those corresponding keys outside of the NumPad would be pretty useless."


I've been working on a module that handles editboxes, so maybe I could add an option to convert the raw scan codes into the expected numbers (only when an edit box is active).
Prime
User Offline
Joined: 15th Jun 2022
Location:
Posted: 24th Jul 2022 06:09
In Windows, GetCharBuffer() returns 0 1 2 3 4 5 6 7 8 9 when the keypad keys are pressed, in Html5 nothing is returned
In Windows, GetRawLastKey() returns 96 97 98 99 100 101 102 103 104 105
In Html5, GetRawLastKey() returns 45 187 40 34 37 12 39 36 38 33 if numlock is active. If numlock is not active then the same keycodes are returned except 5 doesn't register


test program


// Project: testscancodes
// Created: 22-07-23

// show all errors

SetErrorMode(2)

// set window properties
SetWindowTitle( "testscancodes" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 )


gcbuff$ as string = ""


do

s$ = GetCharBuffer()
if len(s$) then gcbuff$ = s$


Print( ScreenFPS() )
Print( "GetCharBuffer() " + gcbuff$ )
// windows 0 1 2 3 4 5 6 7 8 9
Print( "GetRawLastKey() " + str(GetRawLastKey()))
// windows 96 97 98 99 100 101 102 103 104 105
// html5 45 187 40 34 37 12 39 36 38 33

// KEY_NUMLOCK 144
// html5 numlock 282
Print( "Numlock: " + str(GetRawKeyState( 144 )))

Sync()
loop

Prime
User Offline
Joined: 15th Jun 2022
Location:
Posted: 24th Jul 2022 06:11
My solution is https://github.com/charlesgriffiths/agk-modules/tree/main/other/editboxes

If the appropriate variable is set, the numeric keypad keys (.0123456789) will work properly in an editbox, but the left and right arrow keys can't be used to move the cursor position because the keycodes overlap.
Prime
User Offline
Joined: 15th Jun 2022
Location:
Posted: 24th Jul 2022 06:13
Relevant code from module

Prime
User Offline
Joined: 15th Jun 2022
Location:
Posted: 24th Jul 2022 16:19
I posted in haste last night, and after more testing this morning I have updated the module. The html5 keypad behavior is the same on both classic and studio.

relevant code


Definitely not a perfect solution. You can use the mouse to position the editbox cursor but if you type numbers too fast, sometimes the cursor gets out of position. I found the cursor stays in place better when translating the keycode on GetRawKeyReleased() than on GetRawKeyPressed()

Login to post a reply

Server time is: 2022-08-09 08:24:49
Your offset time is: 2022-08-09 08:24:49