Jump to content
caladan1

Problem with hotkeys interfering with other programs' hotkeys

Recommended Posts

Hi. I recently started using AutoIt after having some dealbreaking issues with AutoHotkey (the shortcut keys script froze at random times). The problem with AutoIt is that the hotkeys I set affect all programs not just those selected through WinActive.
 

e.g. I set a hotkey F2 that calls a function F2key() that send a shortcut key is a certain window is active. Now why F2 doesn't work anymore in a different program while this script is running? This is very, very annoying. Any help?

Share this post


Link to post
Share on other sites

Because the AutoIt script "consumes" the F2 key. This example in the help file explains how to send F2 to another application (replace Esc with F2):

; capture and pass along a keypress
HotKeySet("{Esc}", "captureEsc")
Func captureEsc()
    ; ... can do stuff here
    HotKeySet("{Esc}")
    Send("{Esc}")
    HotKeySet("{Esc}", "captureEsc")
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
HotKeySet("{f2}","F2Key")

Func F2Key()
  ; Firefox: save image
  If WinActive("[CLASS:MozillaWindowClass]") Then
    $pos=MouseGetPos()
    MouseClick("left", $pos[0], $pos[1], 2)
  EndIf
 
  ; MusicBee: Locate selected track in library
  If WinActive("[CLASS:WindowsForms10.Window.8.app.0.141b42a_r7_ad1]") Then
    Send("^{f2}")
  EndIf
EndFunc


That F2 doesn't affect only Firefox and MusicBee but other programs like TotalCommander (F2 doesn't work anymore in this program). Why this stupid behaviour and what is the solution?

Share this post


Link to post
Share on other sites

What I want is that F2 to affect just specific programs I want, like AutoHotKey with e.g. #IfWinActive, ahk_class MozillaWindowClass. NOT all programs.

Share this post


Link to post
Share on other sites

Try:

HotKeySet("{f2}", "F2Key")

Func F2Key()
    ; Firefox: save image
    If WinActive("[CLASS:MozillaWindowClass]") Then
        $pos = MouseGetPos()
        MouseClick("left", $pos[0], $pos[1], 2)
    EndIf

    ; MusicBee: Locate selected track in library
    If WinActive("[CLASS:WindowsForms10.Window.8.app.0.141b42a_r7_ad1]") Then
        HotKeySet("{f2}")
        Send("{f2}")
        HotKeySet("{f2}", "F2Key")
    EndIf
EndFunc   ;==>F2Key

Not sure but could also be you want this:

HotKeySet("{f2}", "F2Key")

Func F2Key()
    ; Firefox: save image
    If WinActive("[CLASS:MozillaWindowClass]") Then
        $pos = MouseGetPos()
        MouseClick("left", $pos[0], $pos[1], 2)

    ; MusicBee: Locate selected track in library
    ElseIf WinActive("[CLASS:WindowsForms10.Window.8.app.0.141b42a_r7_ad1]") Then
        Send("^{f2}")
    Else
        HotKeySet("{f2}")
        Send("{f2}")
        HotKeySet("{f2}", "F2Key")
    EndIf
EndFunc   ;==>F2Key

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
18 minutes ago, Jos said:

Try:

HotKeySet("{f2}", "F2Key")

Func F2Key()
    ; Firefox: save image
    If WinActive("[CLASS:MozillaWindowClass]") Then
        $pos = MouseGetPos()
        MouseClick("left", $pos[0], $pos[1], 2)
    EndIf

    ; MusicBee: Locate selected track in library
    If WinActive("[CLASS:WindowsForms10.Window.8.app.0.141b42a_r7_ad1]") Then
        HotKeySet("{f2}")
        Send("{f2}")
        HotKeySet("{f2}", "F2Key")
    EndIf
EndFunc   ;==>F2Key

Not sure but could also be you want this:

HotKeySet("{f2}", "F2Key")

Func F2Key()
    ; Firefox: save image
    If WinActive("[CLASS:MozillaWindowClass]") Then
        $pos = MouseGetPos()
        MouseClick("left", $pos[0], $pos[1], 2)

    ; MusicBee: Locate selected track in library
    ElseIf WinActive("[CLASS:WindowsForms10.Window.8.app.0.141b42a_r7_ad1]") Then
        Send("^{f2}")
    Else
        HotKeySet("{f2}")
        Send("{f2}")
        HotKeySet("{f2}", "F2Key")
    EndIf
EndFunc   ;==>F2Key

Jos

Thanks a lot! The second version is what I want. Basically that hotkey should work only on specific programs (local hotkey) and otherwise work as default (e.g. F2 in Explorer = Rename files/folders).

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

×
×
  • Create New...