Seminko Posted April 22, 2018 Share Posted April 22, 2018 (edited) I wrote a little script that sends a key into an app at random times. The idea is that I must be able to use my computer while this is being done hence the window switching. As per the script below, it will: block user input save the current active window to a variable switch to the app window and wait until it is active send characters check whether the original active window still exists (and if it's not active) and if so switch back unblock user input #RequireAdmin Opt("WinTitleMatchMode", 3) While WinExists("app") Update() Sleep(Random(15000, 22000)) WEnd Func Update() BlockInput(1) $title = WinGetTitle('') WinActivate("app") WinWaitActive("app") Send("{Numpad2}") If WinExists($title) = True And WinActive($title) = False Then WinActivate($title) WinWaitActive($title) EndIf BlockInput(0) EndFunc What happens to me, though, is that from time to time my mouse disappears and and I can't use it until I do a CTRL + ALT + DEL which might indicate that there has been some issue unblocking the input. At first I thought that it might be because in my original script I wasn't checking for whether the original window still existed and it might have ceased to exist when the Update function wanted to switch back to the window. But even though I updated the script to check for that, it still "freezes" / hides the mouse from time to time. The only thing that I can think off that might influence anything is that right when the Update function blocks my input I'm holding a specific key or mouse button, maybe a modifier key or something but I haven't been able to replicate it. Any ideas? Edited April 22, 2018 by Seminko Link to comment Share on other sites More sharing options...
JohnOne Posted April 22, 2018 Share Posted April 22, 2018 Any reason why you cannot use ControlSend AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Seminko Posted April 22, 2018 Author Share Posted April 22, 2018 (edited) 26 minutes ago, JohnOne said: Any reason why you cannot use ControlSend I have been struggling with ControlSend for all my time coding in AutoIt. The way I understand it is that you can only interact with windows which contain controls identifiable with the AutoIt Window Info tool. A good deal of applications do not have any specific identifiable controls. Am I missing something? EDIT: just tried the code below but doesn't work. I'm working with my employer's app and it seems it might have it blocked? ControlSend("app", "", "", "{ESCAPE}") Edited April 22, 2018 by Seminko Link to comment Share on other sites More sharing options...
Seminko Posted April 22, 2018 Author Share Posted April 22, 2018 Well I guess I figured it out. The issue is probably with WinWaitActive. The original active window for some reason disappears and WinWaitActive is blocking the function from finishing and unblocking user's input. 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