ricky Posted November 3, 2015 Share Posted November 3, 2015 Hello,I create a program with :HotKeySet("{ENTER}", "_Search") HotKeySet("{F3}", "_Search")When the focus is on this program, no problem, but if I work with another program, the keys are blocked only for this program. It's possible to activate this function only when this program is focused?Thanks for your help Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 3, 2015 Moderators Share Posted November 3, 2015 Ricky,Look at GUISetAccelerators - like HotKeys but only active when the GUI is active.M23 abberration 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JohnOne Posted November 3, 2015 Share Posted November 3, 2015 I'll assume by "when this program is focused" can translate to "When the application window is active".WinActive ought to do it. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
ricky Posted November 3, 2015 Author Share Posted November 3, 2015 (edited) Thanks for your answers, I already tried with GUISetAccelerators, but the program in an infinite loop.How to reset the GuiGetMsg()?For info : Opt('GUIOnEventMode', 1) is set in the program @JohnOne, I don't understant what can I do with winactive. Could you please be more explicit? Edited November 3, 2015 by ricky Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 3, 2015 Moderators Share Posted November 3, 2015 ricky,That makes no sense at all - all AutoIt scripts have to have an infinite loop to stay alive. And what does GUIGetMsg have to do with it if you are using OnEvent mode?If you are unsure how to use GUISetAccelerators in OnEvent mode then here is the Help file example converted to that mode:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt('GUIOnEventMode', 1) Example() Func Example() GUICreate("Custom MsgBox", 225, 80) GUISetOnEvent($GUI_EVENT_CLOSE, "_Close") GUICtrlCreateLabel("Please select a button.", 10, 10) Local $idYes = GUICtrlCreateButton("Yes", 10, 50, 65, 25) GUICtrlSetOnEvent($idYes, "_Yes") Local $idNo = GUICtrlCreateButton("No", 80, 50, 65, 25) GUICtrlSetOnEvent($idNo, "_No") Local $idExit = GUICtrlCreateButton("Exit", 150, 50, 65, 25) GUICtrlSetOnEvent($idExit, "_Exit") ; Set GUIAccelerators for the button controlIDs, these being Ctrl + y and Ctrl + n Local $aAccelKeys[2][2] = [["^y", $idYes], ["^n", $idNo]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) ; Display the GUI. While 1 Sleep(10) WEnd EndFunc ;==>Example Func _Close() MsgBox($MB_SYSTEMMODAL, "You selected", "Close") Exit EndFunc Func _Yes() MsgBox($MB_SYSTEMMODAL, "You selected", "Yes") Exit EndFunc Func _No() MsgBox($MB_SYSTEMMODAL, "You selected", "No") Exit EndFunc Func _Exit() MsgBox($MB_SYSTEMMODAL, "You selected", "Exit") Exit EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
TheDcoder Posted November 3, 2015 Share Posted November 3, 2015 Maybe his "infinite" loop isn't a GUI loop? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
JohnOne Posted November 3, 2015 Share Posted November 3, 2015 @JohnOne, I don't understant what can I do with winactive. Could you please be more explicit?Func _search() If not WinActive("your window") Then return ;your stuff EndFunc AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
EmilyLove Posted November 5, 2015 Share Posted November 5, 2015 Try thisexpandcollapse popup;Variable to remember hotkey status. This prevents unnecessary work on the CPU constantly Re-(Dis)enabling hotkeys. Global $HotkeyStatus = False ;Launch a Notepad to test Hotkey focus. ShellExecute("notepad.exe") ;Wait for a Window with the Class:Notepad to Exist. WinWait("[CLASS:Notepad]") ;Get Handle of Class:Notepad; Assign to Variable $handle. Global $handle = WinGetHandle("[CLASS:Notepad]") ;Idle Function. This keeps the script alive. idle() Func idle() ;This is the Idle Loop. While 1 ;If Window is Active(Focused) then enable Hotkeys. If WinActive($handle) = True Then If Not $HotkeyStatus = True Then StartHotkeys() ;Else Window is Not Active(Focused) and disables the Hotkeys. Else If Not $HotkeyStatus = False Then StopHotkeys() EndIf ;Sleep for the duration of a single frame to render onscreen. Sleep(1000 / @DesktopRefresh) ;If Window does not exist, exit script. If Not WinExists($handle) Then Exit ;ends the Idle Loop. WEnd EndFunc ;==>idle Func StopHotkeys() ;Stops the Hotkey. HotKeySet("{space}") ;Track the Hotkey Status $HotkeyStatus = False EndFunc ;==>StopHotkeys Func StartHotkeys() ;Starts the Hotkey. HotKeySet("{space}", "FunctionA") ;Track the Hotkey Status $HotkeyStatus = True EndFunc ;==>StartHotkeys Func FunctionA() ;A simple message box to inform the user that the hotkey is working. MsgBox(0, "Space Pressed", "") EndFunc ;==>FunctionA Link to comment Share on other sites More sharing options...
Ourumov94 Posted October 3, 2019 Share Posted October 3, 2019 On 11/5/2015 at 5:20 AM, BetaLeaf said: Try this Thanks a lot BetaLeaf it was very helpful for me! EmilyLove 1 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