Floppy Posted December 15, 2012 Share Posted December 15, 2012 Hello, I have an input box. How can I know if there's the cursor into it? I tried this, but it doesn't work: $addressBar = GUICtrlCreateInput("", 142, 41, 761, 28) If BitAND(GUICtrlGetState($addressBar), $GUI_FOCUS) Then [code here] EndIf Thank you Link to comment Share on other sites More sharing options...
Andreik Posted December 15, 2012 Share Posted December 15, 2012 Did you tried using ControlGetFocus() function? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Floppy Posted December 15, 2012 Author Share Posted December 15, 2012 Did you tried using ControlGetFocus() function?ControlGetFocus is for external windows. Link to comment Share on other sites More sharing options...
Andreik Posted December 15, 2012 Share Posted December 15, 2012 $hMain = GUICreate("Example") For $Index = 1 To 5 GUICtrlCreateInput("",100,$Index*30 + 100,200,20) Next GUISetState(@SW_SHOW,$hMain) Do TrayTip("Focused",ControlGetFocus("Example"),1) Sleep(10) Until GUIGetMsg() = -3 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Floppy Posted December 16, 2012 Author Share Posted December 16, 2012 $hMain = GUICreate("Example") For $Index = 1 To 5 GUICtrlCreateInput("",100,$Index*30 + 100,200,20) Next GUISetState(@SW_SHOW,$hMain) Do TrayTip("Focused",ControlGetFocus("Example"),1) Sleep(10) Until GUIGetMsg() = -3 What about if window title changes every 2 seconds? Isn't possible to use GUICtrlGetState? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 16, 2012 Moderators Share Posted December 16, 2012 Floppy,The trick is to get the window handle as soon as possible - that never changes. M23 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...
Floppy Posted December 16, 2012 Author Share Posted December 16, 2012 (edited) Ok, I tried using ControlGetFocus, but it returns Edit1 instead of $addressBar. Why? Edited December 16, 2012 by Floppy Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 16, 2012 Moderators Share Posted December 16, 2012 Floppy, And what does the Help file say you will get as a return from that function? M23 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...
Floppy Posted December 16, 2012 Author Share Posted December 16, 2012 Returns the ClassNameNN of the control that has keyboard focus within a specified window. For that reason I asked: Isn't possible to use GUICtrlGetState? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 16, 2012 Moderators Share Posted December 16, 2012 (edited) Floppy,Isn't possible to use GUICtrlGetState?What have you tried so far to test? M23Edit; Have you though of _WinAPI_GetFocus? Edited December 16, 2012 by Melba23 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...
Floppy Posted December 16, 2012 Author Share Posted December 16, 2012 _WinAPI_GetFocus retrieves the handle of the window that has the keyboard focus.What about if the focus is in another input field of the same window?I tried the following:$addressBar = GUICtrlCreateInput("", 142, 41, 761, 28) If BitAND(GUICtrlGetState($addressBar), $GUI_FOCUS) Then [code here] EndIfbut it doesn't work, and I don't know why... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 16, 2012 Moderators Share Posted December 16, 2012 Floppy, _WinAPI_GetFocus retrieves the handle of the window that has the keyboard focusAnd what is a control but another window? I see I will have to show you: #include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $cInput_1 = GUICtrlCreateInput("One", 10, 10, 200, 20) $cInput_2 = GUICtrlCreateInput("Two", 10, 50, 200, 20) GUISetState() $iSec = @SEC While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If $iSec <> @SEC Then $iSec = @SEC If _WinApi_GetFocus() = GUICtrlGetHandle($cInput_1) Then ConsoleWrite("Input 1 has focus" & @CRLF) ElseIf _WinApi_GetFocus() = GUICtrlGetHandle($cInput_2) Then ConsoleWrite("Input 2 has focus" & @CRLF) Else ConsoleWrite("No idea!" & @CRLF) EndIf EndIf WEnd All clear? M23 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...
Floppy Posted December 16, 2012 Author Share Posted December 16, 2012 That works, but now I have another problem. I set a hotkey, so when Enter is pressed the function EnterKeyPressed is called. #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <IE.au3> Opt("GUIOnEventMode", 1) HotKeySet("{Enter}", "EnterKeyPressed") $ie = ObjCreate("Shell.Explorer.2") $appMainWindow = GUICreate("Form1", 977, 586, 192, 146) $ieObject = GUICtrlCreateObj($IE, 0, 75, 976, 506) $addressBar = GUICtrlCreateInput("", 142, 41, 761, 28) Func EnterKeyPressed() If _WinApi_GetFocus() = GUICtrlGetHandle($addressBar) Then $addressBarContent = GUICtrlRead($addressBar) If $addressBarContent <> "" Then _IENavigate($ie, $addressBarContent, 0) Else _IENavigate($ie, "about:blank", 0) EndIf EndIf EndFunc If you try that script you'll notice that Enter doesn't work anymore, except in the field $addressBar. Why this happens? Thank you for your help! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 16, 2012 Moderators Share Posted December 16, 2012 (edited) Floppy, Why this happens?Because you have set {ENTER} to be a HotKey and so it is always eaten up by the HotKey command. When it is fired it will only action when the focus is on the input. What else do you want the {ENTER} key to do? M23 P.S. And if you post code, at least make sure it is runnable without the user needing to add lines. Edit: Try this script where we set and unset the HotKey as required - I can use the {ENTER} key in the edit control without problem: expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <IE.au3> Opt("GUIOnEventMode", 1) $oIE = ObjCreate("Shell.Explorer.2") $appMainWindow = GUICreate("Form1", 800, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetBkColor(0xC4C4C4) $oIEObject = GUICtrlCreateObj($oIE, 0, 75, 600, 425) $addressBar = GUICtrlCreateInput("", 10, 10, 500, 20) $cEdit = GUICtrlCreateEdit("", 610, 10, 180, 480) GUISetState() While 1 Sleep(10) If _WinAPI_GetFocus() = GUICtrlGetHandle($addressBar) Then HotKeySet("{Enter}", "EnterKeyPressed") Else HotKeySet("{Enter}") EndIf WEnd Func _Exit() Exit EndFunc Func EnterKeyPressed() $addressBarContent = GUICtrlRead($addressBar) If $addressBarContent <> "" Then _IENavigate($oIE, $addressBarContent, 0) Else _IENavigate($oIE, "http://about:blank", 0) EndIf EndFunc ;==>EnterKeyPressed Any use? M23 Edited December 16, 2012 by Melba23 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...
Floppy Posted December 17, 2012 Author Share Posted December 17, 2012 Thank you Now it works Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 17, 2012 Moderators Share Posted December 17, 2012 Floppy, Glad I could help. M23 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...
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