Sign in to follow this  
Followers 0
frank10

IsPressed with BlockInput strange behaviour ?

10 posts in this topic

#1 ·  Posted (edited)

I'm trying to start a func after a user presses ctrl-e or another key.

I must block user input, so I use BlockInput.

The problem is: after the func, if you press the ctrl it starts again, also without the 'e' key. Sometimes it starts an infinite loop always triggering that func.

Try this simplified version to test it:

Global  $dll = DllOpen("user32.dll")
While 1
Sleep('100')
    ;ctrl - e
    if _IsPressed('11', $dll)  and _IsPressed('45', $dll) then _Start()

WEnd

Func _Start()

   BlockInput ( 1 )

   Run("Notepad.exe", "", @SW_MAXIMIZE)

   WinWaitActive( "Untit" )

   BlockInput ( 0 )
   MsgBox(0,'','')

EndFunc

It seems that the 'e' or both keys remain always pressed after the first time, so only pressing ctrl starts the func or it starts an infinite loop.

Without the blockInput it works well...

What's wrong with this code?

I'm using Autoit 3.2.2, but it's the same with older beta.

Edited by frank10

Share this post


Link to post
Share on other sites



I think your making it more difficult than it needs to be

HotKeySet("^e", "_Start")
While 1
Sleep('100')

WEnd

Func _Start()

   BlockInput ( 1 )

   Run("Notepad.exe", "", @SW_MAXIMIZE)

   WinWaitActive( "Untit" )

   BlockInput ( 0 )
   MsgBox(0,'','')

EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I think your making it more difficult than it needs to be

Well, I have a lot of shortcuts, so I thought to use Ispressed to avoid changing some assignments made with HotKeyset, inside other funcs.

Anyway I tried your version, but it keeps the 'ctrl' pressed after the first time.

So, are there problems with Hotkeyset, too?

Anyway, it seems strange to me it doesn't work well the combo Ispressed-Blockinput...

now, also Hotkeyset-Blockinput....

Share this post


Link to post
Share on other sites

Well, I have a lot of shortcuts, so I thought to use Ispressed to avoid changing some assignments made with HotKeyset, inside other funcs.

Anyway I tried your version, but it keeps the 'ctrl' pressed after the first time.

So, are there problems with Hotkeyset, too?

Anyway, it seems strange to me it doesn't work well the combo Ispressed-Blockinput...

now, also Hotkeyset-Blockinput....

I'm not seeing the control key still being held down with the hotkeyset.

How are you determining this?


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I'm not seeing the control key still being held down with the hotkeyset.

How are you determining this?

You run the script from Scite, then press ctrl-e. Notepad fires up and the msgbox. You close msgbox and notepad.

Don't press ctrl.

Go to Scite and scroll down-up with the mouse wheel: you get a zoom-in-out instead of the simple scroll up-down.

Or

if you have some windows opened, after the func fired, select some window in the taskbar at the bottom of the screen: you will multi select windows instead of switching between them...

Share this post


Link to post
Share on other sites

You run the script from Scite, then press ctrl-e. Notepad fires up and the msgbox. You close msgbox and notepad.

Don't press ctrl.

Go to Scite and scroll down-up with the mouse wheel: you get a zoom-in-out instead of the simple scroll up-down.

Or

if you have some windows opened, after the func fired, select some window in the taskbar at the bottom of the screen: you will multi select windows instead of switching between them...

Ok, now I see what you mean, seems like odd behaviour.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

It doesn't seem odd to me. Think about it for a moment. You hold down Ctrl and press e. Within milliseconds you disable user-input. Unless you can manage to release the Ctrl key within those few milliseconds, you lock yourself into a state where the Ctrl key is down. Windows will never get the key-up message when you release Ctrl since you disabled user input before you released the key. That message won't appear later after you re-enable user input because the input is not buffered for later playback.

Share this post


Link to post
Share on other sites

#include <misc.au3>
Global $dll = DllOpen("user32.dll")
While 1
    Sleep('100')
    ;ctrl - e
    If _IsPressed('11', $dll) And _IsPressed('45', $dll) Then _Start()

WEnd

Func _Start()
    Do
        Sleep(20)
    Until Not _IsPressed('11', $dll)

    BlockInput(1)

    Run("Notepad.exe", "", @SW_MAXIMIZE)

    WinWaitActive("Untit")

    BlockInput(0)
    MsgBox(0, '', '')
EndFunc


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

It doesn't seem odd to me. Think about it for a moment.

Ok, this seems an explanation.

But how do you determine if the user has released the key? The ctrl, alt or every other key.

If I make a Sleep('300') it could be safe for some fast user but there could be someone slower, getting the error.

If I increase the sleep time I could get too much lag in the script.

I can't always send a ctrl up because there are some other alt combo shortcuts.

Furthermore, sometimes I don't get the ctrl locked, but the other key pressed in combination. Of course those keys vary too.

Anyway I found something that seems to contradict your explanation: I put a 1 sec sleep before the Blockinput and I released only the 'e' key. So you should expect the ctrl is still locked: instead it works well...

I can't say the users: 'Be fast when you press your shortcuts, otherwise...' :P

@herewasplato

This is a solution, but it has some drawbacks:

that same func is called from different parts, sometimes from the user, other times from the script itself. In this case there is no ctrl pressed.

EDIT: I made wrong assumption in this case...

Furthermore, this is a tricky method to track all the func and all the shortcuts if they are numerous.

Some shortcuts could have ctrl, other alt or mixed combo. It begins difficult to track down all these and to remember to correct all if I change my shortcut...

Another drawback it could be when a user deselect first the ctrl than the other key. it is rare but it occured to me sometimes.

So, it should be another better solution. What do you suggest?

Edited by frank10

Share this post


Link to post
Share on other sites

So, I have to choose Ispressed, because I must call that same func with different arguments, with different keys and Hotkeyset doesn't pass arguments...

Say I have a ctrl-1 to call the func with one argument, ctrl-2 with another one and so on.

So I made:

If _IsPressed(&apos;11&apos;, $dll) And _IsPressed(&apos;31&apos;, $dll) Then
            _Start(&apos;0&apos;, &apos;0&apos;)
        EndIf

        If _IsPressed(&apos;11&apos;, $dll) And _IsPressed(&apos;32&apos;, $dll) Then
            _Start(&apos;0&apos;, &apos;1&apos;)
        EndIf
 oÝ÷ Ùë6²oyÛay¹hrH§¦ëi®åzl"¶aÆ®¶­s`¢gVæ2õ7F'Bb33c·&V2ÒÂb33c·VÂÒb33³"b33²¢fÇC¶æFVçBfwC´bô5&W76VBb33³b33²Âb33c¶FÆÂFVâ6VæBb33·´5E$ÅUÒb33²¢bô5&W76VBb33³3b33²Âb33c¶FÆÂFVâ6VæBb33³b33²¢bô5&W76VBb33³3"b33²Âb33c¶FÆÂFVâ6VæBb33³"b33²¢WF2âࢢ&Æö6´çWB¢fÇC²öæFVçBfwC°

Now it works well with no lag.

The only drawbacks are to track down and update all the combo key and the fact you must send

a key to the current app. In my case it's ok, but if you have, say, a word edit window...

Maybe could it be possible to send them to an invisible window?

btw: how do you indent code in the forum edit panel? I tried the indent command with no luck.

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