caladan1 Posted June 11, 2017 Share Posted June 11, 2017 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 More sharing options...
Danp2 Posted June 11, 2017 Share Posted June 11, 2017 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. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
water Posted June 11, 2017 Share Posted June 11, 2017 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
caladan1 Posted June 11, 2017 Author Share Posted June 11, 2017 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 More sharing options...
caladan1 Posted June 11, 2017 Author Share Posted June 11, 2017 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. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 11, 2017 Developers Share Posted June 11, 2017 (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 June 11, 2017 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 More sharing options...
caladan1 Posted June 11, 2017 Author Share Posted June 11, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now