Jump to content

Recommended Posts

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted (edited)

Ok, I tried using ControlGetFocus, but it returns Edit1 instead of $addressBar. Why?

Edited by Floppy
  • Moderators
Posted

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:

  Reveal hidden contents

 

  • Moderators
Posted (edited)

Floppy,

  Quote

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:

  Reveal hidden contents

 

  • Moderators
Posted

Floppy,

  Quote

_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:

  Reveal hidden contents

 

Posted

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! :)

  • Moderators
Posted (edited)

Floppy,

  Quote

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:

  Reveal hidden contents

 

  • Moderators
Posted

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...