Jump to content

BlockInput issue?


Recommended Posts

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:

  1. block user input
  2. save the current active window to a variable
  3. switch to the app window and wait until it is active
  4. send characters
  5. check whether the original active window still exists (and if it's not active) and if so switch back
  6. 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 by Seminko
Link to comment
Share on other sites

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 by Seminko
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...