Jump to content
Sign in to follow this  
Seminko

Temporarily Disable Hotkey Filtering - "a" not working

Recommended Posts

Seminko

Hey guys,

I am trying to temporarily disable hotkeys set in a script and came across THIS ('?do=embed' frameborder='0' data-embedContent>>) thread.

I got it working nicely, finally after a few days of fiddling around. BUT, the "a" button is not working!

Please see my script

While 1
    $CurWindowEx = WinGetTitle("active")
    If $CurWindowEx = "app" Then
           HotkeySet ("a", "something1")
       HotkeySet ("s", "something2")
       HotkeySet ("d", "something3")
       HotkeySet ("f", "something4")
       HotkeySet ("g", "something5")
       HotkeySet ("h", "something6")
    Elseif $CurWindowEx <> "app" Then    
           HotkeySet ("a", "SendA")
       HotkeySet ("s", "SendS")
       HotkeySet ("d", "SendD")
       HotkeySet ("f", "SendF")
       HotkeySet ("g", "SendG")
       HotkeySet ("h", "SendH")
    EndIf
    Sleep(1000)
WEnd

Func SendA ()
   Send("a")
   Sleep(25)
EndFunc

Func SendS ()
   Send("s")
   Sleep(25)
EndFunc

Func SendD ()
   Send("d")
   Sleep(25)
EndFunc

Func SendF ()
   Send("f")
   Sleep(25)
EndFunc

Func SendG ()
   Send("g")
   Sleep(25)
EndFunc

Func SendH ()
   Send("h")
   Sleep(25)
EndFunc

So when I am in the desired app ALL hotkeys work and the script does what it should for EVERY hotkey.

BUT, when I'm in ie Notepad, "a" does not work. Shift+a produces correctly "A" but plain and simple lower "a" does not work.

The strange thing is that every other character works nicely in the lower version as well as in the capital one. All except of "a".

Any ideas please?

Share this post


Link to post
Share on other sites
Melba23

Seminko,

Welcome to the AutoIt forum. :)

I would just disable the HotKeys rather than continually resetting them to do what the native key does already. Try this and see if it works for you:

; Create a flag to show whether we are in the "app"
Global $fFlag = False

While 1
    $CurWindowEx = WinGetTitle("active")
    If $CurWindowEx = "app" And $fFlag = False Then
        ; Set the Hotkeys
        HotKeySet("a", "something1")
        HotKeySet("s", "something2")
        HotKeySet("d", "something3")
        HotKeySet("f", "something4")
        HotKeySet("g", "something5")
        HotKeySet("h", "something6")
        ; Set the flag
        $fFlag = True
    ElseIf $CurWindowEx <> "app" And $fFlag = True Then
        ; Unset the Hotkeys
        HotKeySet("a")
        HotKeySet("s")
        HotKeySet("d")
        HotKeySet("f")
        HotKeySet("g")
        HotKeySet("h")
        ;Clear the flag
        $fFlag = False
    EndIf
    Sleep(100)
WEnd
Now you only change the HotKeys when you really need to, which is why I have reduced the Sleep time. You obviously need to add all the "app" functions. ;)

Let me know how you get on, and please do ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Seminko

Hello Melba23, this made me realize that I had a flaw in my script preventing the script from writing the lower case "a".

I've re-done the script to match your idea but now it seems that AutoIT thinks the "app" is always the active window, even though I'm AltTabbed to Chrome, for example.

Should I rather use if WinActive?

 

EDIT: BTW, didn't know you can do HotKeySet("a"). Sometimes the easiest solution is the right one :)

EDIT2: Oh nevermind. Figured it out! It should say: WinGetTitle("[Active]"). Thank you very much Melba23!

Edited by Seminko

Share this post


Link to post
Share on other sites
Melba23

Seminko,

Glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Seminko

Actually, I'm expanding the script and getting stuck again. Maybe you can help ;)

The script works fine as it is but I wanted to further improve it in a way so that the functions get activated only if a specific color is not present.

Here's what I got:

Global $fFlag = False

While 1
    $CurWindowEx = WinGetTitle("[Active]")
    $result = PixelSearch(746, 790, 1257, 813, 0x18181B, 10)
    If $CurWindowEx = "app" And $fFlag = False And IsArray($result) = False Then ;If the app is the active window and PixelSearch does not find the color, it should trigger functions
       HotkeySet ("a", "Something1")
       HotkeySet ("s", "Something2")
       HotkeySet ("d", "Something3")
       HotkeySet ("f", "Something4")
       HotkeySet ("g", "Something5")
       HotkeySet ("h", "Something6")
       $fFlag = True
    ElseIf $CurWindowEx = "app" And $fFlag = False And IsArray($result) = True Then ;If the app is the active window and PixelSearch does in fact find the color, it should not trigger functions but just letters
       HotKeySet("a")
       HotKeySet("s")
       HotKeySet("d")
       HotKeySet("f")
       HotKeySet("g")
       HotKeySet("h")
       $fFlag = False
    Elseif $CurWindowEx <> "app" And $fFlag = True Then ;If the app is not the active window, it should trigger letters only.
       HotKeySet("a")
       HotKeySet("s")
       HotKeySet("d")
       HotKeySet("f")
       HotKeySet("g")
       HotKeySet("h")
       $fFlag = False
    EndIf
    Sleep(100)
WEnd

To my surprise it works only when I restart the script. It works for a while and then it starts executing the functions only.

Edited by Seminko

Share this post


Link to post
Share on other sites
Melba23

Seminko,

I have tested this on my machine with one of my "app"s and it seesm to work as you require: ;)

Global $fFlag_App = False, $fFlag_Pixel = False

While 1
    ; Check active window
    $CurWindowEx = WinGetTitle("[Active]")
    If $CurWindowEx = "app" Then
        If $fFlag_App = False Then ; Will only fire as the "app" becomes active
            ; Set the flag
            $fFlag_App = True
        Else ; Will fire as long as "app" remains the active window after it has become active
            ; Check the pixel
            $result = PixelSearch(746, 790, 1257, 813, 0x18181B, 10)
            If IsArray($result) And $fFlag_Pixel = False Then ; If the app is the active window and PixelSearch finds the color, it should not trigger functions but just letters
                HotKeySet("a")
                HotKeySet("s")
                HotKeySet("d")
                HotKeySet("f")
                HotKeySet("g")
                HotKeySet("h")
                $fFlag_Pixel = True
            ElseIf (Not IsArray($result)) And $fFlag_Pixel = True Then; If the app is the active window and PixelSearch does not find the color, it should trigger functions
                HotKeySet("a", "Something1")
                HotKeySet("s", "Something2")
                HotKeySet("d", "Something3")
                HotKeySet("f", "Something4")
                HotKeySet("g", "Something5")
                HotKeySet("h", "Something6")
                $fFlag_Pixel = False
            EndIf
        EndIf
    ElseIf $CurWindowEx <> "app" And $fFlag_App = True Then
        HotKeySet("a")
        HotKeySet("s")
        HotKeySet("d")
        HotKeySet("f")
        HotKeySet("g")
        HotKeySet("h")
        $fFlag_App  = False
        $fFlag_Pixel = False
    EndIf
    Sleep(100)
WEnd
Does it work on your machine with your "app"? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Seminko

Awesome! Works very nicely. Occasionally does not reset but that's easily fixed.

BTW, $fFlag_Pixel is there because of the reset? It stores the info in the tag so you can manipulate it - reset?

Thanks a million!

Share this post


Link to post
Share on other sites
Melba23

Seminko,

 

BTW, $fFlag_Pixel is there because of the reset?

No, it acts in the same way as $fFlag_App to prevent setting or unsetting the HotKeys on each pass. :)

By using the flags the setting/unsetting only takes place when the state (either "app" is active/inactive or the pixel is/is not present) changes. This prevents unnecessary action by the script - if you were running a big function on every pass it would really slow the script down; while if you were updating a control doing so on every pass usually leads to quite bad flickering. Using flags means you only action the code when needed.

Glad you got it working. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Seminko

Yea, I meant that! But apparently I did not explain myself well :-D

Share this post


Link to post
Share on other sites
Melba23

Seminko,

 

Yea, I meant that!

Then I am delighted I could confirm your supposition! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Seminko

Well apparently, when I ALT+TAB out of the application the script stops working. I have to pop up the window where the pixel is and that resets the script and it works again.

Share this post


Link to post
Share on other sites
Melba23

Seminko,

What exactly is this "app" in you are using these HotKeys? Perhaps there is a better way to do what you want without relying on pixel detection, which I have never found particularly reliable. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Melba23

Hi,

It now appears that this is a game-related script - so what happens next should come as no surprise to anyone. :naughty:

M23

P.S. If it does come as a surprise, I suggest you read the Forum rules (there is also a link at bottom right of each page) as soon as possible. ;)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×