Jump to content

_ispressed doesn't work correctly


Zoli1972
 Share

Recommended Posts

I wrote a little code to disable pressing CTRL-key while a certain application window is visible. I tried to disable i.e. opening files by pressing CTRL+O that way. Unfortunately it doesnt always work. As long as I press CTRL my function works, but if I release CTRL and press O without pressing CTRL after that, the "file Open" dialog pops up. It seems to me, that pressing CTRL remains in AutoIt's memory somehow. How can I get rid of this problem?

Below the code I am using:

include <Misc.au3>

$dll = DllOpen("user32.dll")

While 1
    Sleep ( 20 )
    Select
        Case _IsPressed("11", $dll); BUG If Ctrl key isn't pressed anymore, but i.e. "o" is, the Ctrl key remains in memory somehow and everything reacts like it still would be pressed
            If WinActive("My Window") Then  
                BlockInput(1)
            EndIf
        Case Not _IsPressed("11", $dll)
            BlockInput(0)   
    EndSelect
WEnd
DllClose($dll)

Zoli

Link to comment
Share on other sites

Hmmm... my guess is that blockinput isn't doing what you think its doing... possibly blocking future input? I'll have to check.

Anyway... try this:

While 1
    Sleep(200)
    If WinActive("My Window") Then
        HotKeySet("^o", "stop")
    Else
        HotKeySet("^o")
    EndIf
WEnd

Func stop ()
    MsgBox(0, "", "This ctrl+o was stopped.")
EndFunc

Seems to work for me.

Hope that helps.

Brick

Link to comment
Share on other sites

Hmmm... my guess is that blockinput isn't doing what you think its doing... possibly blocking future input? I'll have to check.

Anyway... try this:

While 1
    Sleep(200)
    If WinActive("My Window") Then
        HotKeySet("^o", "stop")
    Else
        HotKeySet("^o")
    EndIf
WEnd

Func stop ()
    MsgBox(0, "", "This ctrl+o was stopped.")
EndFunc

Seems to work for me.

Hope that helps.

Brick

That seems like a good solution.

I tried playing with the Zoli19721's script and found that this version works but I don't really understand why the blockinut has the effect it does

#include <Misc.au3>

$Blocked = False
While 1
    Sleep ( 20 )
    Select
        Case _IsPressed("11") And Not $blocked; BUG If Ctrl key isn't pressed anymore, but i.e. "o" is, the Ctrl key remains in memory somehow and everything reacts like it still would be pressed
            If WinActive("Untitled") Then
                BlockInput(1)
                $Blocked = True
            EndIf
        Case (Not _IsPressed("11", $dll)) And $blocked
            BlockInput(0)
                      ;ensure ctrl key is set back up, {CTRLUP} alone doesn't work for me.
            Send("{CTRLDOWN}")
            Sleep(100)
            Send("{CTRLUP}")
            $blocked = False
    EndSelect
WEnd
DllClose($dll)
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...