Jump to content

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?

Link to comment
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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
Share on other sites

  • Developers

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 etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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).

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