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.

Bug Reports / [DBP 7.5] Inkey$() issue after calling some Windows functions

Author
Message
Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 13th Dec 2010 19:23
Hi all,

The Inkey$() function returns its lastest entry infinitely after calling some Windows functions.

I add this issue while I was using my own dll functions, so first I thought the problem came from my dll.

Windows fuctions tested : ChooseColor(), MessageBox() & GetOpenFileName()


So I decided to test the behaviour of the Inkey$() function using only DBP commands : unfortunatly there's the same issue.


Self explanatory : Copy, Paste and Run the code below.

Press any key (except "Q" to quit) : everything will be ok.

Press the "T" key then click and click and click... endless because Inkey$() doesn't seems to read correctly the keyboard.





Notes :

- Using Scancode() instead of Inkey$() works fine.

- I made some other tests and I noticed that calling "Wait Key" after the Window function seems to reset the keyboard management in some way and make Inkey$() works again.

- Using Clear Entry Buffer doesn't solve the problem.

I Hope this will help.


Cheers,

Chris
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 13th Dec 2010 22:19
Hmmm, it's a bug of windows' making by the looks of it.

DBPro gets the 'key down' windows event with no problem, then you open up a new window that captures any future windows events such as 'key up' and DBPro doesn't see them - if DBPro doesn't get the 'key up' event, then it doesn't know you've let go of the key.

SCANCODE() uses a completely different method of determining a keypress, and doesn't give the same results - use the following program, press and hold 'a', then press and release 's' and you'll see what I mean:


I don't know just yet how to fix this problem, but there's a work-around you can use that fits with your current code:


Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 14th Dec 2010 00:13 Edited at: 14th Dec 2010 16:14
Hi IanM,


Quote: "
SCANCODE() uses a completely different method of determining a keypress, and doesn't give the same results - use the following program, press and hold 'a', then press and release 's' and you'll see what I mean:"


Yes indeed.
This example makes me think to a keyboard driver I've written years ago for a DOS game dev kit.

Keyboard management was (and is still) tricky : I'am a little bit desapointed that windows does't provide much easier functions to use for this purpose.

e.g. using scancode : pressing a higher value scancode key (right arrow) without releasing a lower one (left arrow) will just make the higher key pressed to be ignored.

I still got the full asm code but it's overdated and will be certainly useless as I had to access to the BIOM and some keyboard ports if I'am not wrong.
I assume Windows won't let the users to access such low level stuff.



Quote: "
ScanKey = scancode()
if ScanKey > 0
Key$ = InKey$()
else
Key$ = ""
endif"


Clever!

Thank you very much IanM!



Edit :
The work-around code is great but it is not suitable (as this) when the program uses both Scancode() and Inkey$() functions : pressing any key which doesn't return a character will of course make Inkey$() to return a bad char.

So I tried to play around with this problem and I made some tests using the GetFocus() and SetFocus() windows function without success : it seems Inkey$() doesn't work this way.

Please IanM, I have one question : can you tell me what windows ressource the Inkey$() function uses?

Thanks



Cheers,

Chris
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Dec 2010 14:39
INKEY$() is updated by the windows message pump. It gets key down and key up messages automatically and uses those to update the value returned, except when another window highjacks the messages (such is the case with any dialog window such as MessageBox).

In this case, the key up messages are being 'lost'.

Chris66
14
Years of Service
User Offline
Joined: 12th Aug 2009
Location:
Posted: 17th Dec 2010 10:53
Thank you very much for these informations!

Cheers,

Chris

Login to post a reply

Server time is: 2024-04-20 11:50:20
Your offset time is: 2024-04-20 11:50:20