Weird keypress bug in GFX?

New to FreeBASIC? Post your questions here.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Weird keypress bug in GFX?

Postby datwill310 » Jun 15, 2017 16:18

In the game I'm making, I've noticed a strange behaviour with my keyboard where if I hold the Function key and F11 (on my keyboard it turns up volume), it acts as a B key press in my game (I use FBGFX, multikey, and the scancodes).

Is this a bug with the library or my game that I should look out for? Or is it not a bug at all and the scancode combination of Fn+F11 = B for some reason?
Last edited by datwill310 on Jun 23, 2017 14:19, edited 1 time in total.
sancho2
Posts: 547
Joined: May 17, 2015 6:41

Re: Weird bug?

Postby sancho2 » Jun 16, 2017 0:45

I can't reproduce the error, though I don't know what you mean by 'function key' and f11.
f11 is a function key. And I tried it with ctrl, alt, windows key, shift, capslock, numlock.

Code: Select all

#Include "fbgfx.bi"
Using fb
ScreenRes 800, 600
Dim l As Long = 0
Do
   If MultiKey(SC_B) Then Cls: Print "hello"
   Print l
   l += 1
Loop While Not InKey = Chr(27)

Another keyboard I have has a 'FN' key between the right alt, and ctrl keys. This is used to access secondary functions of certain keys.
It to does not register as a 'b' on F11 or any other function key.
I suspect it is a quirk of the driver for your keyboards extra functionality.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Weird bug?

Postby datwill310 » Jun 16, 2017 6:30

Thanks for your post.
I was able to trigger the "hello!" event using both B and FN+F11.
This is an image of the keyboard I am using (I don't think it's the exact model but it's close enough):
Image
In between the Alt Gr and Menu keys is the FN key I've found on pretty much all keyboards I've used. It may have been in different places on the keyboard, or in another colour altogether (usually blue). I have been surprised to not find the FN key on so many keyboards while researching though!
On this keyboard too, you can use the combination FN+F11 to turn the volume up (this is shown on the keyboard F11 key in the image above - though granted not very clearly :D) - which the driver uses to turn the volume up.
Yes, I'm thinking too that it may just be the way the driver/keyboard works. But just posting to clarify :).
TeeEmCee
Posts: 300
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Weird bug?

Postby TeeEmCee » Jun 23, 2017 13:51

I think it's almost certainly a fbgfx bug, where it misinterprets some unusual keypress events.
Are you using Windows?
There is surely a utility somewhere (I could provide one if needed) which prints out information about win32 keypress events as they occur. If you posted the output of that we could look at it and try to figure out why it's happening.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Weird bug?

Postby datwill310 » Jun 23, 2017 14:09

TeeEmCee wrote:Are you using Windows?
There is surely a utility somewhere (I could provide one if needed) which prints out information about win32 keypress events as they occur. If you posted the output of that we could look at it and try to figure out why it's happening.

Yes, I am using Windows.
I will look for a piece of software like this and I will post any results.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Weird bug?

Postby datwill310 » Jun 23, 2017 14:18

TeeEmCee wrote:There is surely a utility somewhere (I could provide one if needed) which prints out information about win32 keypress events as they occur. If you posted the output of that we could look at it and try to figure out why it's happening.

I have used the software at delphiforfun.org and have found the following:
The first paragraph describes me pressing the B key, the second paragraph describes me pressing the key combination FN and F11, and the third paragraph describes me pressing the F11 key.
I have included KeyDown event exits.
OnKeyDown, Key code=66, Control keys=, Key name b
OnKeyPress b
OnKeyup, Key code=66, Control keys=, Key name b

OnKeyDown, Key code=175, Control keys=, Key name ..........Unassigned
OnKeyup, Key code=175, Control keys=, Key name ..........Unassigned

OnKeyDown, Key code=122, Control keys=, Key name F11
OnKeyup, Key code=122, Control keys=, Key name F11
TeeEmCee
Posts: 300
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Weird bug?

Postby TeeEmCee » Jun 23, 2017 14:33

OK, thanks. Key 175 is VK_VOLUME_UP.

I just had a look at the code, and it seems that multikey does not return the results from listening to win32 events. It depends on which fbgfx driver is in use: there are three: gdi, opengl and ddraw. ddraw uses DirectInput to poll the keyboard state, while the others use the win32 function GetKeyboardState.
It doesn't appear that the GetKeyboardState code could possibly create a bad 'B' key press, but the DirectInput codepath looks really dubious. In fact, I notice that a keycode of 176 would cause 'B' to appear to be pressed, and maybe there is an off-by-one I'm not aware of.

Could you check which driver is in use?

Code: Select all

' (Whatever 'screen' command)
dim driver as string
screeninfo  , , , , , , driver
?driver
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Weird bug?

Postby datwill310 » Jun 23, 2017 14:36

TeeEmCee wrote:Could you check which driver is in use?

Code: Select all

' (Whatever 'screen' command)
dim driver as string
screeninfo  , , , , , , driver
?driver

I've not actually put it in the game code, but I've initialised the same screen mode with the same settings and am using DirectX.
TeeEmCee
Posts: 300
Joined: Jul 22, 2006 0:54
Location: Auckland

Re: Weird keypress bug in GFX?

Postby TeeEmCee » Jun 23, 2017 15:04

Looking closer, I see this is really complicated. The ddraw driver calls IDirectInputDevice_SetDataFormat to set the format of the array of data (keystate in the code below) that it wants: it's given an array of 256 key specifications. I don't understand the specifications, the documentation is surprisingly unhelpful, and fbgfx's source code has been obfuscated by not using the original constant and macro names from the documentation.

But then at gfx_driver_ddraw.c (lin 460) certain keys are aliased together:

Code: Select all

                /* Simplicistic way to deal with extended scancodes */
                for (i = 0; i < 128; i++)
                    __fb_gfx->key[i] = ((keystate[i] | keystate[i + 128]) & 0x80) ? TRUE : FALSE;

I think the comment points to the bug.

If you look at this list of DirectInput scan codes you see that F11 is 47. And it's close to FB's scancode for B, which is 48.
Also I notice that VK_VOLUME_UP, 175, is 128+47, a modified version of the F11 key?

I don't have more time to look into this right now. Maybe in a couple weeks.
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Weird keypress bug in GFX?

Postby datwill310 » Jun 23, 2017 15:15

TeeEmCee wrote:Looking closer, I see this is really complicated.

This IS complicated o_O. I want to thank you for doing this.
adele
Posts: 47
Joined: Jun 13, 2015 19:33

Re: Weird keypress bug in GFX?

Postby adele » Jun 26, 2017 21:10

Hi datwill310,

obviously you try to assign certain keystrokes to actions in your game. As a general driver cannot "know" all KB layouts (and the corresponding return codes) I suggest to let the user define which keyboard hits should be assigned to these actions. I had seen this kind of "setup" in many old MS-DOS programs, even on CBM C64 machines, and your program just would have to "remember" the scan codes, not even the name of the key actually chosen.

Let us assume you want to assign a key to the function "move right", no matter if the user hits one of the keys "r", ">" or <right> or <right on numpad> or s.th. totally unexpected, the chosen key can be associated with the function.

Just an idea...

adi
datwill310
Posts: 355
Joined: May 29, 2015 20:37

Re: Weird keypress bug in GFX?

Postby datwill310 » Jun 26, 2017 21:25

adele wrote:Hi datwill310,

obviously you try to assign certain keystrokes to actions in your game. As a general driver cannot "know" all KB layouts (and the corresponding return codes) I suggest to let the user define which keyboard hits should be assigned to these actions. I had seen this kind of "setup" in many old MS-DOS programs, even on CBM C64 machines, and your program just would have to "remember" the scan codes, not even the name of the key actually chosen.

Let us assume you want to assign a key to the function "move right", no matter if the user hits one of the keys "r", ">" or <right> or <right on numpad> or s.th. totally unexpected, the chosen key can be associated with the function.

Just an idea...

adi

Thanks for the idea, I do allow the user to chose between pretty much all the keyboard scan codes for every action ;) - if this is what you mean. And you can even use a gamepad.
I was talking about the B key because that is the default key for one of those actions and I'm using the default controls.
EDIT: or do you mean assigning multiple keys to one action?

Return to “Beginners”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests