Sign in to follow this  
Followers 0
Tankbuster

Console App / Clear or catch Keyboard buffer

2 posts in this topic

Currently I face a small but annoying problem.

I stripped down the problem for you (I will not bother you with the rest of the code, because the problem is re-creatable with this few lines)

==============================================================================================================================================

Let me explain: I wrote a console app, that more or less loops until something happens.

During this time if a key is pressed, the keystroke is "catched" and sent to the console after the app exit.

Example output of console:

C:\>CONSOLE_KEY_DEMO.EXE
(now the app is running and is in the While loop)
(now I press the keys abc and then F1 to exit the app
C:\>abcS

As you can see the "abc" and also the "F1" key are sent to the console. (F1 will repeat the last Command on single char base on the position the the "S" is from CON"S"OLE_KEY_DEMO.EXE

#Include <Misc.au3>
$dll = DllOpen("user32.dll")
    While  1
        if _ispressed("70",$dll) then exit(11)
    WEnd
    exit (1)

I search the docu and the forum but I can't get an idea how to get rid of the input.

ConsoleRead()? Isn't there a way to flush the input?

BTW: No, this is no keylogger bs or a bot or what ever, just a console app in autoit, so please do not comment this post in case you fear the app is such a crap.

I will appreciate if you post me a link to the correct solution ( I hope for my self that it is not written in the default docu......) or for any other solution you offer to me. If you need more info just ask and I will post (but I think it should be clear what my problem is about)

Thank you already

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Similar issue I have.

What I would like to do is: flushing the current input buffer.

I have written a code which determines wheter the user pressed a mousebutton or the keys 1 till 5, but there should always be one key pressed at the most. For instance, if the user presses the mousebutton and afterwards one of the keys, the mousebutton should get released.

But as it goes for an input buffer, it still "thinks" that the mousebutton is pressed too.

Code of concern:

Opt("MouseClickDelay", $MouseClickDelay) ;10
Opt("MouseClickDownDelay", 0)
Opt("SendKeyDelay", $SendKeyDelay) ;20
Opt("SendKeyDownDelay", $SendKeyDownDelay) ;30

*snip*

If _IsPressed("31", $dll) Or _IsPressed("32", $dll) Or _IsPressed("33", $dll) Or _IsPressed("34", $dll) Or _IsPressed("35", $dll) Then
    $WaitingForRightClick = True
EndIf

If _IsPressed("01", $dll) And _IsPressed("02", $dll) = False And $WaitingForRightClick = False Then
    If IsArray(PixelSearch($Coords[0], $Coords[1], $Coords[2], $Coords[3], 16777215)) = 1 Then
        Send($RSlot)
        MouseDown("right")
    Else
        Send($LSlot)
        MouseDown("right")
    EndIf
    MouseUp("right")
EndIf

If either key betweeen 1 and 5 is pressed, $WaitingForRightClick is set as True. Therefore, it should never access the 2nd "If" Statement.

But it does it for a short time during pressing one of those keys.

Any ideas on how to prevent this? Tryed sleep(x) everywhere, tryed, mouseclick with different clickspeeds ranging from 0 - x.

Edited by misterioes

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