caladan1

Problem with hotkeys interfering with other programs' hotkeys

7 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

You haven't shown any of your code, so we are only left to assume what you are doing. Suggest that you read the help file entry for GUISetAccelerators.

Share this post


Link to post
Share on other sites

#3 ·  Posted

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

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

#5 ·  Posted

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

#6 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted

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