Sign in to follow this  
Followers 0
Skizmata

Keyboard/Send Bug/Issue

6 posts in this topic

#1 ·  Posted (edited)

I'm working on a somewhat complicated AS400 automation program to help me in my work. Basically the program just does allot of mouseclick(), Send() and sleep() however a strange bug has cropped up from time to time where after the program ends (for one reason or another but never due to a crash out) something is left wrong with the keyboard. Its acts somewhat like a key is stuck but its not physically stuck. Is there a way to reset the keyboard/mouse at the end of my program or is this caused by something else anyone knows of.

If nothing comes to mine would there be any way to disable the mouse and keyboard during these automated steps? (and better yet to disable it all except the abort hotkey)

Thank you all very much,

Below is an excerpt from the end of my script. The whole thing is extremely similar.

Thanks again.

send($WorkOrderNumber & @cr)
    sleep(1000)
    send("C{TAB}" & Spacer($QuantityScraped,15,1))
    sleep(1000)
    send(@cr)
        sleep(1000)
    send("{F3}")

    
    send("{F3}")
    sleep(2000)
    send("{TAB 7}")

    Send(Spacer($ManHours,9,1))

    send("{TAB 9}        0")
    send("{TAB 9}        0")
    send("{TAB 9}        0")
    TogglePause()
    send(@cr)
    sleep(1500)
    send("{F3}")
EndFunc

P.S. If I'm pulling the status bar info from my as400 emulator with StatusbarGetText() but I don't want to use the window Title because it changes to often... Is there another way to identify that window in StatusbarGetText() other then the Title.

Edited by Skizmata

AutoIt changed my life.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

When you say "somewhat like a key is stuck but its not physically stuck", do you mean that the script spams a key multiple times like its stuck in a loop? Or do you mean that the key does not spam but you have to reset the key by pressing it again.

I came across this same issue with MacroGamer. You might wan't to just send both the key down and key ups, instead of just sending the key. Sometimes in MacroGamer a key is still left down, I got around this by doing a trick like _ClearKeyboardCache() function in MacroGamer script. It loops through the keyboard keys and if the key is still pressed, then just press that key again to unstick it. Im sure you can get around it though by carefully sending the down and the up for each key sent. Check out the help file for sending up's and down's.

Edited by Toady

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Share this post


Link to post
Share on other sites

What Opt()'s did you set anyway?

I ran across a similar situation over a year ago when running a script to automate betting/swimming/gun-buying/gambling etc. in Grand Theft Auto S.A., I was really puzzled, until I found out that I accidentally set KeyDownDelay to 5000 so the LShift key (in my case) would stay pressed for 5 seconds...

It's a longshot, you probably didn't code this totally drunk like me that evening, but this is all I can think of, and IF it helps uncovering your error I would be really amused by my alcohol-induced errors helping someone :whistle:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Couple of questions:

Do you use a GUI?

If you don't then you can skip reading the remaining of this post.

It happened to me once: I created a GUI for sending commands to a terminal window, run it and noticed something strange - if the window where I tried to send was not active, the command was sent to the active window (which was my GUI) causing the Start button to be pressed again and again and this made me believe that somehow the start function is executed over and over. I posted this on the forum and got help and the solution was to be SURE that whenever trying to SEND something I have to be SURE that the window is ACTIVE.

I will suggest that you need to make the window active before each Send command.

(you can replace "Send" by "WinActivate(...)" followed by "Send")

Another Idea - if the application changes the title frequently - maybe there is a part of the title which is common and you can use that. If NOT then you can get the handle and use it.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

When I was testing the WinSetTrans (transparency) function for the first time in SciTE

an error in my coding caused the SciTE editor window to get the Fade Out GUI command instead of the gui code.

SciTE faded out of existance before my eyes....

had to close it in process explorer, no data lost though.

shows the importance of tight HWnd And ControlID when sending commands to windows.. :whistle:

to follow up the suggestion above about using partial window Title to get handle and status bar problem..

Use Mode 2 to get partial Title or Mode 4 and use Class

AutoItSetOption("WinTitleMatchMode", 4)
;3 examples
$handle = WinGetHandle("Untitled - Notepad", ""); Full Title, wont work once document is saved with name or document opened
$handle = WinGetHandle("[TITLE:Untitled - Notepad; CLASS:Notepad]", ""); using Title and Class properties
$handle = WinGetHandle("[CLASS:Notepad]", ""); Use Class if Title not useful with Mode 2 partial match, get Class with AutoIt Window Info Utility
; or
AutoItSetOption("WinTitleMatchMode", 2)
If WinExists("Notepad", "") Then
   $handle = WinGetHandle("Notepad", ""); partial title, use consistent part of title if any to get window HWND
EndIf
AutoItSetOption("WinTitleMatchMode", 4) ; Return to WinTitleMatchMode 4, use HWNDS and Control iD's

WinActivate($handle, "")
WinWaitActive($handle, "",5)
WinSetOnTop(handle, "", 1)

$text = StatusbarGetText($handle, "", 1); use $handle instead of Title

; help file says there are problems with reading some status bars

you could use WinActivate in a loop to maintain window focus While sending commands

If Not WinActive($handle) Then WinActivate($handle)

I did this with a utility i automated with an autoit wrapper prog and tested it by constantly

clicking on other windows while it was sending commands to the program i was automating to steal focus.

after a lot of trial and error i found in my case, using Sleep, ControlFocus and WinWaitActive commands in the

wrong place and time cause most of the problems with losing window focus.

I can now click on and cycle through other programs minimized in the taskbar at hi speed and not break the program focus as it executes commands.

Using HWND's and ControlID's with ControlSend, ControlCommand, ControlClick etc, and getting program feedback

really helps for reliability instead of using Send.

for programs that don't automate well i suggest a look at the functions in AutoLib3 here on the forum


I see fascists...

Share this post


Link to post
Share on other sites

I came across this same issue with MacroGamer. You might wan't to just send both the key down and key ups, instead of just sending the key. Sometimes in MacroGamer a key is still left down, I got around this by doing a trick like _ClearKeyboardCache() function in MacroGamer script. It loops through the keyboard keys and if the key is still pressed, then just press that key again to unstick it. Im sure you can get around it though by carefully sending the down and the up for each key sent. Check out the help file for sending up's and down's.

Thank you very much Toady I actually remembered this from the MacroGamer (I'm a huge fan) source code and hoped you would comment on my situation. I will try the key up and key down insted of key preses. If that doesn't work out for me would it be alright if I borrowed the _ClearKeyBoardCache function so at the end of my script I too could be sure everything was undone?

What Opt()'s did you set anyway?

It's a longshot, you probably didn't code this totally drunk like me that evening, but this is all I can think of, and IF it helps uncovering your error I would be really amused by my alcohol-induced errors helping someone :lmao:

I was not totally drunk but being such a rookie coder is sometimes like being drunk. I did have some options set that didn't make allot of sense to me. I have since reexamined them and removed one. Thank you very much for your anecdote.

Couple of questions:

Do you use a GUI?

If you don't then you can skip reading the remaining of this post.

It happened to me once: I created a GUI for sending commands to a terminal window, run it and noticed something strange - if the window where I tried to send was not active, the command was sent to the active window (which was my GUI) causing the Start button to be pressed again and again and this made me believe that somehow the start function is executed over and over. I posted this on the forum and got help and the solution was to be SURE that whenever trying to SEND something I have to be SURE that the window is ACTIVE.

I will suggest that you need to make the window active before each Send command.

(you can replace "Send" by "WinActivate(...)" followed by "Send")

Another Idea - if the application changes the title frequently - maybe there is a part of the title which is common and you can use that. If NOT then you can get the handle and use it.

I do have a GUI and have a couple WaitWinActive's in there but prolly not enough I thought they would cause a delay but after further examination they don't seem to cause any delay at all if the window is active.

When I was testing the WinSetTrans (transparency) function for the first time in SciTE

an error in my coding caused the SciTE editor window to get the Fade Out GUI command instead of the gui code.

SciTE faded out of existance before my eyes....

had to close it in process explorer, no data lost though.

shows the importance of tight HWnd And ControlID when sending commands to windows.. :whistle:

to follow up the suggestion above about using partial window Title to get handle and status bar problem..

Use Mode 2 to get partial Title or Mode 4 and use Class

AutoItSetOption("WinTitleMatchMode", 4)
;3 examples
$handle = WinGetHandle("Untitled - Notepad", ""); Full Title, wont work once document is saved with name or document opened
$handle = WinGetHandle("[TITLE:Untitled - Notepad; CLASS:Notepad]", ""); using Title and Class properties
$handle = WinGetHandle("[CLASS:Notepad]", ""); Use Class if Title not useful with Mode 2 partial match, get Class with AutoIt Window Info Utility
; or
AutoItSetOption("WinTitleMatchMode", 2)
If WinExists("Notepad", "") Then
   $handle = WinGetHandle("Notepad", ""); partial title, use consistent part of title if any to get window HWND
EndIf
AutoItSetOption("WinTitleMatchMode", 4); Return to WinTitleMatchMode 4, use HWNDS and Control iD's

WinActivate($handle, "")
WinWaitActive($handle, "",5)
WinSetOnTop(handle, "", 1)

$text = StatusbarGetText($handle, "", 1); use $handle instead of Title

; help file says there are problems with reading some status bars

you could use WinActivate in a loop to maintain window focus While sending commands

If Not WinActive($handle) Then WinActivate($handle)

I did this with a utility i automated with an autoit wrapper prog and tested it by constantly

clicking on other windows while it was sending commands to the program i was automating to steal focus.

after a lot of trial and error i found in my case, using Sleep, ControlFocus and WinWaitActive commands in the

wrong place and time cause most of the problems with losing window focus.

I can now click on and cycle through other programs minimized in the taskbar at hi speed and not break the program focus as it executes commands.

Using HWND's and ControlID's with ControlSend, ControlCommand, ControlClick etc, and getting program feedback

really helps for reliability instead of using Send.

for programs that don't automate well i suggest a look at the functions in AutoLib3 here on the forum

This is all especially helpful to me as it seems we where working on a similar project. I didn't really understand how to deal with the fact that the title of my AS400 emulator changed frequently but this has it covered. Thank you very much. This will be incorporated into my program by noon. ;)

This forum is great! As a long time forum goer I cant believe my post got 4 responses that where ALL on topic ALL pertinent to my question and no one flaming me for being an AutoIt beginner!!! You guys rock!!!


AutoIt changed my life.

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