GetAsyncKeyState

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

GetAsyncKeyState

Post by bdevel »

I wrote an application in c++ which should return the GetAsyncKeyState(0x01). But I always get 0. If I click on the window of my app,I will get the right answer. GetAsyncKeyState should return systemwide clicks! The same things happens when I write a VB application.
I found an app written in Delphi which uses the GetAsyncKeyState call and returns systemwide clicks. Can someone tell me whats the reason? And how can I fix this.

THX


I tried wine-0.9.59 and wine-0.9.60
Dan Kegel

GetAsyncKeyState

Post by Dan Kegel »

On Thu, May 8, 2008 at 5:51 AM, bdevel <[email protected]> wrote:
I wrote an application in c++ which should return the GetAsyncKeyState(0x01). But I always get 0. If I click on the window of my app,I will get the right answer. GetAsyncKeyState should return systemwide clicks! The same things happens when I write a VB application.
I found an app written in Delphi which uses the GetAsyncKeyState call and returns systemwide clicks.
Even when run in Wine?
bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

Post by bdevel »

Yes. In vmware the apps I wrote returning systemwide mouseclicks!
And as I said the Delphi app returns in wine systemwide mouseclicks. I tried hook too with the same results.

I can post an example sourcecode but everyone knows how to call the GetAsyncKeyState function.

printf("Mouse state %08X\n",GetAsyncKeyState(0x01)); // for example
Last edited by bdevel on Thu May 08, 2008 8:10 am, edited 1 time in total.
Dan Kegel

GetAsyncKeyState

Post by Dan Kegel »

On Thu, May 8, 2008 at 6:01 AM, bdevel <[email protected]> wrote:
Yes.... the Delphi app reeturns in wine systemwide mouseclicks.
Then try running both it and your app with
WINEDEBUG=+relay
to see what they're doing differently.
bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

Post by bdevel »

ok I will try this.
bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

Post by bdevel »

wine AsyncKeyTest.exe WINEDEBUG=+relay doesn't return anything. Could you please explain how I should use the WINEDEBUG=+relay command.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: GetAsyncKeyState

Post by vitamin »

bdevel wrote:I found an app written in Delphi which uses the GetAsyncKeyState call and returns systemwide clicks. Can someone tell me whats the reason? And how can I fix this.
It's a long known problem. And you can't fix it without modifying Wine and X server. Wine can not know what keys are pressed outside of programs' window.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

Post by bdevel »

But why the Delphi app can do this while it runs in wine?
Dan Kegel

GetAsyncKeyState

Post by Dan Kegel »

On Thu, May 8, 2008 at 6:19 AM, bdevel <[email protected]> wrote:
wine AsyncKeyTest.exe WINEDEBUG=+relay doesn't return anything. Could you please explain how I should use the WINEDEBUG=+relay command.
It's an environment variable. Either you can do

WINEDEBUG=+relay
export WINEDEBUG
wine AsyncKeyTest.exe
unset WINEDEBUG

or, more concisely,

WINEDEBUG=+relay wine AsyncKeyTest.exe

Vitamin's probably right, i.e. we don't believe the delphi app
actually does what you claim.
But what the heck, if it does, +relay will tell you what it's doing.
Ove Kaaven

GetAsyncKeyState

Post by Ove Kaaven »

vitamin skrev:
bdevel wrote:
I found an app written in Delphi which uses the GetAsyncKeyState call and returns systemwide clicks. Can someone tell me whats the reason? And how can I fix this.
It's a long known problem. And you can't fix it without modifying Wine and X server. Wine can not know what keys are pressed outside of programs' window.
Pff. Why would you need to modify X server? Using existing XQueryKeymap
ought to be sufficient.
Dan Kegel

GetAsyncKeyState

Post by Dan Kegel »

On Thu, May 8, 2008 at 6:29 AM, bdevel <[email protected]> wrote:
But why the Delphi app can do this while it runs in wine?
We don't believe it can. But hey, we could be wrong.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: GetAsyncKeyState

Post by vitamin »

Ove Kaaven wrote:vitamin skrev:
bdevel wrote:
I found an app written in Delphi which uses the GetAsyncKeyState call and returns systemwide clicks. Can someone tell me whats the reason? And how can I fix this.
It's a long known problem. And you can't fix it without modifying Wine and X server. Wine can not know what keys are pressed outside of programs' window.
Pff. Why would you need to modify X server? Using existing XQueryKeymap
ought to be sufficient.
Well I guess one could use this to query the keyboard state, However like with mouse (GetCursorPos -> XQueryPointer) there are might be some issues.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

bdevel wrote:But why the Delphi app can do this while it runs in wine?
What are you asking? I've told you that Wine has a bug. And you have to fix it if you want your app to work. Or better then that don't use GetAsyncKeyState - it's a really bad thing to relay on.
bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

Post by bdevel »

vitamin wrote: Or better then that don't use GetAsyncKeyState - it's a really bad thing to relay on.
Ok then show me a better solution to get the keystates. But I think this bug has to be fixed.

I realy love wine (because i can play allmost every windows game). But this bug drives me crazy!
Dan Kegel

GetAsyncKeyState

Post by Dan Kegel »

On Thu, May 8, 2008 at 7:34 AM, bdevel <[email protected]> wrote:
Here is the Delphi app.
That's a scary url.

Better source is http://bugs.winehq.org/show_bug.cgi?id=7874 which points to
http://www.easyuo.com/cheffe/asynckeytest.zip and also lists a code
fragment showing how it's implemented.

That test program doesn't work for me in Wine unless it has the focus,
which kind of defeats the purpose. So I'm not sure what you're talking about
when you say it works in Wine.
bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

Post by bdevel »

Hey thats my own domain. I only use this to share sourcecodes with my friends.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

bdevel wrote:
vitamin wrote: Or better then that don't use GetAsyncKeyState - it's a really bad thing to relay on.
Ok then show me a better solution to get the keystates. But I think this bug has to be fixed.

I realy love wine (because i can play allmost every windows game). But this bug drives me crazy!
GetKeyState() is what you should use. Getting "global" key states are bad. If you really have to do that, then you doing something really wrong.

Also patches are welcome. That bug won't be fixed any time soon. So you better fix your program instead.

DO NOT post that app here, it will be removed
Markus Hitter

GetAsyncKeyState

Post by Markus Hitter »

Am 08.05.2008 um 15:26 schrieb vitamin:
Wine can not know what keys are pressed outside of programs' window.
Some people would see a feature here. Some gentle sandboxing isn't
that bad.


Markus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/
User avatar
L. Rahyen
Moderator
Moderator
Posts: 338
Joined: Fri Feb 22, 2008 9:13 pm

GetAsyncKeyState

Post by L. Rahyen »

On Thursday May 8 2008 17:09:28 vitamin wrote:
Getting "global" key states are bad.
If you really have to do that, then you doing something really wrong.
Actually sometimes there is valid reasons for getting global key states. For
example, Mousotron really needs this to be fixed to be fully usable. Today, it
only can "see" mouse motion (globally in the X server) but not mouse/keyboard key presses (outside of its window).
There is some other real-world examples...

Unfortunately this is unlikely to be fixed anytime soon because of some technical difficulties.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: GetAsyncKeyState

Post by vitamin »

L. Rahyen wrote:On Thursday May 8 2008 17:09:28 vitamin wrote:
Getting "global" key states are bad.
If you really have to do that, then you doing something really wrong.
Actually sometimes there is valid reasons for getting global key states. For
example, Mousotron really needs this to be fixed to be fully usable.
The stuff that "needs" global key events called "key logger".

If something _needs_ those events, they should use LL_HOOKs (keyboard and mouse). Constantly polling GetAsyncKeyState() doesn't guarantee anything and is a really bad practice. It's even bad to use that function to check state of the keys at any given point of time.
User avatar
L. Rahyen
Moderator
Moderator
Posts: 338
Joined: Fri Feb 22, 2008 9:13 pm

GetAsyncKeyState

Post by L. Rahyen »

On Friday May 9 2008 23:30:36 vitamin wrote:
L. Rahyen wrote:
On Thursday May 8 2008 17:09:28 vitamin wrote:
Getting "global" key states are bad.
If you really have to do that, then you doing something really wrong.
Actually sometimes there is valid reasons for getting global key states.
For example, Mousotron really needs this to be fixed to be fully usable.
The stuff that "needs" global key events called "key logger".
Not necessary. In my example, - Mousotron, - collects number of keypresses,
it doesn't log anything (it even lacks statistical logging). In real world
this program is useful to see how much text you wrote today or how actively
you used your mouse.
If something _needs_ those events, they should use LL_HOOKs (keyboard and
mouse). Constantly polling GetAsyncKeyState() doesn't guarantee anything
and is a really bad practice. It's even bad to use that function to check
state of the keys at any given point of time.
Well, fact is that (unfortunately) not all developers of Windows programs
really care about good design or good practice. BTW, I'm not sure how exactly
Mousotron works (I didn't actually tried to debug it) so therefore I'm not
sure does it uses this function or not; I just think that there is might be a
such possibility.
bdevel
Level 1
Level 1
Posts: 8
Joined: Thu May 08, 2008 7:38 am

Post by bdevel »

This app shouldn't be a key logger and I usually do not program for windows (the worst OS ever :) ). The app should start/stop pushing a button within a game when I push a button (for example "c"). A friend asked me for such a program!

I also tried hooks but it doesn't work (perhapse I did something wrong, I don't know). A short example would be nice.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

bdevel wrote:This app shouldn't be a key logger and I usually do not program for windows (the worst OS ever :) ). The app should start/stop pushing a button within a game when I push a button (for example "c"). A friend asked me for such a program!

I also tried hooks but it doesn't work (perhapse I did something wrong, I don't know). A short example would be nice.
The topic is closed. We don't write trainers/cheats/other bad stuff.
Locked