Sign in to follow this  
Followers 0
Mikesch

_IsPressed and Keyboard buffer

6 posts in this topic

Hi,

the following will work fine for about 2 seconds, sending "x" and "y" alternating, then output will be sorted. So if I press the defined $hotkey for some seconds, I'll end up with something like

xyxyxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyy.

Guess it has to do with the keyboard buffer or message queuing, but I can't find out why this would happen or how to avoid it.

Could you point me to the right direction, please?

Func Sendkeys()
    While _IsPressed($hotkey, $dll) = 1

        Send("x")
        sleep(100)
        Send("y")
        sleep(100)
    WEnd
EndFunc   ;==>Sendkeys

Thanks,

Mike

Share this post


Link to post
Share on other sites



Hi billo,

thanks for your reply. I know your code would work, and I even don't have issues when using F-Keys with _isPressed(), but in this case the function should really only run as long as the defined key ("z") is held down. (The 100 ms delay is crucial, too.)

Send("x") and 'y' will be replaced later, probably with some ControlSend() commands I need for video cutting.

While testing I came about that strange behaviour and still can't see what I'm missing.

Mike

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I dont have problem with this when it is in main loop, you did not post the script that can replicate problem so its hard to know where problem is

#Include <Misc.au3>
While 1
    If _IsPressed("74") Then ;74 = F5   try not to use F1 becose it is mented for help in most of programs
        Send("x")
        Sleep(100)
        Send("y")
        Sleep(100)
    EndIf
WEnd

Edit: ok i know what did you do wrong

You did something like this probably

#Include <Misc.au3>
HotKeySet("{F5}","Sendkeys")
While 1
;~  If _IsPressed("74") Then Sendkeys()
WEnd
Func Sendkeys()
    While _IsPressed("74") = 1

        Send("x")
        sleep(100)
        Send("y")
        sleep(100)
    WEnd
EndFunc   ;==>Sendkeys

So if thats your problem delite hotkey and put ispresed in main loop (probably my crystal ball is working :( )

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Oh, re-reading the script I think the problem occurs because I launch the function by hotkey, so the problem is not within the function itself, but in the way it is called.

Thanks, you helped me very much. "Main Loop" was the correct keyword.

Regards,

Mike

EDIT: Got me! ;-) Even before I did. Crystal ball functioning properly. Thanks again.

Mike

Edited by Mikesch

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0