Jump to content

How to know if in the input box there's the cursor?


Floppy
 Share

Recommended Posts

  • Moderators

Floppy,

The trick is to get the window handle as soon as possible - that never changes. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Floppy,

And what does the Help file say you will get as a return from that function? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Floppy,

Isn't possible to use GUICtrlGetState?

What have you tried so far to test? :)

M23

Edit; Have you though of _WinAPI_GetFocus? ;)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

_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] EndIf

but it doesn't work, and I don't know why...

Link to comment
Share on other sites

  • Moderators

Floppy,

_WinAPI_GetFocus retrieves the handle of the window that has the keyboard focus

And 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

  • Moderators

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? :huh:

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:

#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 by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Floppy,

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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