shmuelw1 Posted October 3, 2011 Share Posted October 3, 2011 I'm trying to create a small script to press a few keys after two mouse clicks. Below is the script that I wrote. For some reason it does the Send command after only one click, then it waits until I click again. #Include <Misc.au3> ; required for _IsPressed $dll = DllOpen("user32.dll") Dim $x = 0 While 1 While $x < 2 If _IsPressed("01", $dll) Or _IsPressed("02", $dll) Then $x = $x + 1 EndIf WEnd Send("{UP 4}{ENTER}{ENTER}") $x = 0 WEnd This version works after one click, and gives me 1 1/2 seconds to make the second click before calling the Send command. But I'd prefer to get AutoIt to wait for the second click without using the Sleep function. Any ideas? While 1 While 1 If _IsPressed("01", $dll) Or _IsPressed("02", $dll) Then ExitLoop WEnd Sleep(1500) Send("{UP 4}{ENTER}{ENTER}") WEnd Link to comment Share on other sites More sharing options...
martin Posted October 3, 2011 Share Posted October 3, 2011 I expect it's because you only test to see if the button is pressed and it will loop round fast and get to a count of 2 before the button is released. You need to wait fo rth ebutton to be released before you check to see if it's pressed again. Something like this maybe but I haven't tested it. #include <Misc.au3> ; required for _IsPressed $dll = DllOpen("user32.dll") Dim $x = 0 While 1 While $x < 2 If _IsPressed("01", $dll) Then waittilnotpressed("01", $x) ElseIf _IsPressed("02", $dll) Then waittilnotpressed("02", $x) EndIf WEnd Send("{UP 4}{ENTER}{ENTER}") $x = 0 WEnd Func waittilnotpressed($skey, ByRef $y) $y = $y + 1 While _IsPressed($skey, $dll) Sleep(20) WEnd EndFunc ;==>waittilnotpressed Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
kylomas Posted October 3, 2011 Share Posted October 3, 2011 (edited) shmuelw1, Try while $x < 3 kylomas P.S. - Belay my last...does NOT work Edited October 3, 2011 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted October 3, 2011 Share Posted October 3, 2011 shmuelw1, Sorry for the idiot response earlier. Testing and investigation indicate that this is, as Martin says, related to typematic rate and key bounce. One possible solution: low level keyboard handler and increment your counter at mouse up instead of mouse down. For example of LL keyboard handler see the help file or this thread kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now