Jump to content

Why can't I get focus on GuiInput?


Recommended Posts

I have this script

#include <GUIConstants.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{F11}", "_get_controlfocus")
$sHTML = "<HTML>" & @CR
$sHTML &= "<HEAD>" & @CR
$sHTML &= '<style type="text/css"><!-- body { margin: 4px; line-height: 16px;} --></style>'
$sHTML &= "</HEAD>" & @CR
$sHTML &= "<BODY BGCOLOR=""#292929"">"
$sHTML &= "</BODY>"
$sHTML &= "</HTML>"
$oIE = _IECreateEmbedded()
$Form1 = GUICreate("AForm1", 625, 445, 193, 115)
$Edit1 = GUICtrlCreateObj($oIE, 16, 16, 593, 369)
$Input1 = GUICtrlCreateInput("", 116, 408, 100, 20)
$Label1 = GUICtrlCreateLabel("Press F11", 16, 408, 83, 17)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Close")
_IENavigate($oIE, "about:blank")
_IEDocWriteHTML($oIE, $sHTML)
$oBody = _IETagNameGetCollection($oIE, "body", 0)
GUISetState(@SW_SHOW)
While 1
    if ControlGetFocus($Form1) = "Internet Explorer_Server1" then GUICtrlSetState($Input1, $GUI_FOCUS)
    Sleep(10)
WEnd
func _GUI_Close()
    Exit
EndFunc
func _get_controlfocus()
    MsgBox(0, "Get controlfocus", ControlGetFocus($Form1))
EndFunc

and I can't get focus to guiInput when I click on Edit1's obj? Actualy, I can get focus but only if I hold down mouse click on Edit1's obj. ;/

p.s. I tried GUICtrlSetOnEvent($Edit1, "_focus") and setting _focus func: GUICtrlSetState($Input1, $GUI_FOCUS) and that's not working ;/

Link to comment
Share on other sites

I have this script

#include <GUIConstants.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{F11}", "_get_controlfocus")
$sHTML = "<HTML>" & @CR
$sHTML &= "<HEAD>" & @CR
$sHTML &= '<style type="text/css"><!-- body { margin: 4px; line-height: 16px;} --></style>'
$sHTML &= "</HEAD>" & @CR
$sHTML &= "<BODY BGCOLOR=""#292929"">"
$sHTML &= "</BODY>"
$sHTML &= "</HTML>"
$oIE = _IECreateEmbedded()
$Form1 = GUICreate("AForm1", 625, 445, 193, 115)
$Edit1 = GUICtrlCreateObj($oIE, 16, 16, 593, 369)
$Input1 = GUICtrlCreateInput("", 116, 408, 100, 20)
$Label1 = GUICtrlCreateLabel("Press F11", 16, 408, 83, 17)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Close")
_IENavigate($oIE, "about:blank")
_IEDocWriteHTML($oIE, $sHTML)
$oBody = _IETagNameGetCollection($oIE, "body", 0)
GUISetState(@SW_SHOW)
While 1
    if ControlGetFocus($Form1) = "Internet Explorer_Server1" then GUICtrlSetState($Input1, $GUI_FOCUS)
    Sleep(10)
WEnd
func _GUI_Close()
    Exit
EndFunc
func _get_controlfocus()
    MsgBox(0, "Get controlfocus", ControlGetFocus($Form1))
EndFunc

and I can't get focus to guiInput when I click on Edit1's obj? Actualy, I can get focus but only if I hold down mouse click on Edit1's obj. ;/

p.s. I tried GUICtrlSetOnEvent($Edit1, "_focus") and setting _focus func: GUICtrlSetState($Input1, $GUI_FOCUS) and that's not working ;/

ControlGetFocus() returns the ClassNameNN of the control, it does not change the focus. To set the focus use ControlFocus() not GuiCtrlSetState(). Simplified demo:

#include <GUIConstants.au3>
#include <IE.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{F11}", "_SetControlFocus")

$Form1 = GUICreate("AForm1", 625, 445, 193, 115)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Close")

$oIE = _IECreateEmbedded()
$Edit1 = GUICtrlCreateObj($oIE, 16, 16, 593, 369)
_IENavigate($oIE, "about:blank")

$Input1 = GUICtrlCreateInput("", 116, 408, 100, 20)
$Label1 = GUICtrlCreateLabel("Press F11", 16, 408, 83, 17)
GUISetState(@SW_SHOW)

While 1
    $sClassNameNN = ControlGetFocus($Form1)
    TrayTip("Focus", "ClassNameNN = " & $sClassNameNN, 5)
    Sleep(100)
WEnd

Func _GUI_Close()
    Exit
EndFunc

Func _SetControlFocus()
    ControlFocus($Form1, "", $Input1)
EndFunc

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Tnx for reply. I know I get classnameNN with ControlGetFocus, but shouldn't this line set focus on my input:

if ControlGetFocus($Form1) = "Internet Explorer_Server1" then GUICtrlSetState($Input1, $GUI_FOCUS)oÝ÷ صúºÊ',!zr7öhhاj.±æî¶Ú'¢s%©Ýr­¶¬jëh×6#include <GUIConstants.au3>
#include <IE.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{F11}", "_get_controlfocus")
$sHTML = "<HTML>" & @CR
$sHTML &= "<HEAD>" & @CR
$sHTML &= '<style type="text/css"><!-- body { margin: 4px; line-height: 16px;} --></style>'
$sHTML &= "</HEAD>" & @CR
$sHTML &= "<BODY BGCOLOR=""#292929"">"
$sHTML &= "</BODY>"
$sHTML &= "</HTML>"
$oIE = _IECreateEmbedded()
$Form1 = GUICreate("AForm1", 625, 445, 193, 115)
$Edit1 = GUICtrlCreateObj($oIE, 16, 16, 593, 369)
$Input1 = GUICtrlCreateInput("", 116, 408, 100, 20)
$Label1 = GUICtrlCreateLabel("Press F11", 16, 408, 83, 17)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Close")
_IENavigate($oIE, "about:blank")
_IEDocWriteHTML($oIE, $sHTML)
$oBody = _IETagNameGetCollection($oIE, "body", 0)
GUISetState(@SW_SHOW)
While 1
    if ControlGetFocus($Form1) = "Internet Explorer_Server1" then
        MsgBox(0, "ok", "ok")
        GUICtrlSetState($Input1, $GUI_FOCUS)
    EndIf
    Sleep(10)
WEnd
func _GUI_Close()
    Exit
EndFunc
func _get_controlfocus()
    MsgBox(0, "Get controlfocus", ControlGetFocus($Form1))
EndFunc

it's the same code as I posted above, but only msgbox change in the WHILE1 part, and with msgbox it works, how come? I want the SAME effect like in this last example script but without msgbox.

Link to comment
Share on other sites

I've done it:

#include <GUIConstants.au3>
#include <IE.au3>
#Include <Misc.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{F11}", "_get_controlfocus")
$dll = DllOpen("user32.dll")
$oIE = _IECreateEmbedded()
$Form1 = GUICreate("AForm1", 625, 445, 193, 115)
$Edit1 = GUICtrlCreateObj($oIE, 16, 16, 593, 369)
$Input1 = GUICtrlCreateInput("", 116, 408, 100, 20)
$Label1 = GUICtrlCreateLabel("Press F11", 16, 408, 83, 17)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_Close")
_IENavigate($oIE, "about:blank")
$oBody = _IETagNameGetCollection($oIE, "body", 0)
GUISetState(@SW_SHOW)
While 1
    if ControlGetFocus($Form1) = "Internet Explorer_Server1" then
        if _IsPressed("01", $dll) Then
            Do
            Until NOT _IsPressed("01", $dll)
            GUICtrlSetState($Input1, $GUI_FOCUS)
        EndIf
    EndIf
    Sleep(10)
WEnd
func _GUI_Close()
    DllClose($dll)
    Exit
EndFunc
func _get_controlfocus()
    MsgBox(0, "Get controlfocus", ControlGetFocus($Form1))
EndFunc
Edited by sandin
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...