Jump to content

Possible BlockInput "Bug"


Recommended Posts

This isn't exactly a bug, but it's a really annoying problem I just discovered with using BlockInput() as part of a function called by a hot key. Consider this code:

CODE
HotKeySet("^!+a", "my_func");

While 1

Sleep(100)

WEnd

Func my_func()

BlockInput(1)

Sleep(1000)

BlockInput(0)

;Send("{ALTUP}{CTRLUP}{SHIFTUP}")

EndFunc

So when the user presses CTRL + SHIFT + ALT + A, my_func is called. It momentarily blocks input, then unblocks it. The problem arises (I think) because the function gets called before the user releases the keys (they release they probably during the sleep). After the function is called -- even after the script has been shut down -- it is as if you are still holding down CTRL + SHIFT + ALT. It's extremely annoying and confusing if you don't realize what happened (at first I thought my CTRL key was stuck :whistle: ). To fix it, you just have to press each of those keys once (to send the signal to release them) . Uncommenting the last line (that tries to automate the release) doesn't seem to help.

Any ideas on how to prevent this? Do you notice the same behavior when you run the script? I'm not sure I'd say it's a bug, because on some level AutoIT is doing exactly what it's supposed to...On the other hand, it can make your programs have bugs when you're doing pretty much what you're supposed to :lmao:

Link to comment
Share on other sites

You could is If not _ispressed

HotKeySet("^!+a", "my_func");
$var = 0
While 1
Sleep(100)
WEnd


Func my_func()
While $var = 0
If Not _ispressed ("watever alt is") and _ispressed etc Then
$var = 1
Endif
Wend


BlockInput(1)
Sleep(1000)
BlockInput(0)
;Send("{ALTUP}{CTRLUP}{SHIFTUP}")
EndFunc
Link to comment
Share on other sites

That did the trick -- thanks :whistle:

I didn't know about the _IsPressed function

Here's my final code in case anyone comes across this later and is interested

CODE

#Include <Misc.au3>

HotKeySet("^!+a", "my_func");

While 1

Sleep(100)

WEnd

Func my_func()

$switch = 1;

While $switch

If Not (_IsPressed("12") Or _IsPressed("11") Or _IsPressed("10")) Then

$switch = 0;

EndIf

WEnd

BlockInput(1)

Sleep(1000)

BlockInput(0)

EndFunc

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...