Jump to content

Get Focus?


Recommended Posts

I searched the help file with terms like "focus" "input" etc.. and didn't see anything. I've got my GUI and then the standard While loop checking for any new action. I have a long list of input boxes in my gui, and each has default text in. In my loop I want to be able to detect when a user has clicked inside the input, so I can delete (or highlight, either) the default text. I want the text there to start, but it's a pain to backspace through it all when there are so many inputs. Any idea's? Perhaps a simple command that I missed?

My inputs are $input[0] $input[1] etc... up to about 25

Martin helped me out, using an array to check them. His idea is brilliant, and I will definitely use the technique in other area's - but using it for this deletes the text only after you have already deleted it yourself and punched in your new text. What I'm loooking for is a way to read the focus of the control.

Here's the stripped down basics of what I currently have.

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $input[0] To $input[UBound($input) - 1]
            GUICtrlSetData($nMsg, "")
            GUICtrlGetState(
    EndSwitch
WEnd
Link to comment
Share on other sites

So you do:

GuiCtrlSetState(@GUI_CtrlID, $GUI_FOCUS)

Or

GuiCtrlSetState(@GUI_CtrlHandle, $GUI_FOCUS)

I think.

Edit: Added another snippet just in case ;)

Cool, thanks. I looked closer at the @GUI_CtrlID in the help file, and it looks like I need to change the the event mode before I can use it. I started off switching the event mode, but this is the first time I've ever done it like this. Here's what I've got so far. I had an error with the "Case @GUI_CtrlId = $input[0] To $input[uBound($input) - 1]" so I commented it. No error now, but I've still got something wrong. When I open it flashes the gui then immediately closes. Before I can work on the Inputs I need to get the basics down. Any idea on what I'm doing wrong here?

Opt("GUIOnEventMode", 1)

GUICtrlSetOnEvent(@GUI_CtrlId, "_Functions") ; My way, I want to highlight the current text in the inputbox when it is clicked inside of (or "given focus")
;GUICtrlSetOnEvent($Button1, "start") ;<-- The normal way?

While 1
    ;$iScrollPos = Scrollbar_GetPos($GUI, $SB_VERT)
    ;ConsoleWrite($iScrollPos & @CRLF)
    Sleep(10)
WEnd

Func _Functions()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
            MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
        Case @GUI_CtrlId = $GUI_EVENT_RESTORE
            MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            #cs
                Case @GUI_CtrlId = $input[0] To $input[UBound($input) - 1]
                MsgBox(0, "", "one of the input boxes was clicked in")
                ;f ind which one and delete the current contents
            #ce
        Case @GUI_CtrlId = $Button1
            ;function x... keep going down with all the other controls.
    EndSelect
EndFunc   ;==>_Functions
Link to comment
Share on other sites

I searched the help file with terms like "focus" "input" etc.. and didn't see anything. I've got my GUI and then the standard While loop checking for any new action. I have a long list of input boxes in my gui, and each has default text in. In my loop I want to be able to detect when a user has clicked inside the input, so I can delete (or highlight, either) the default text. I want the text there to start, but it's a pain to backspace through it all when there are so many inputs. Any idea's? Perhaps a simple command that I missed?

My inputs are $input[0] $input[1] etc... up to about 25

Martin helped me out, using an array to check them. His idea is brilliant, and I will definitely use the technique in other area's - but using it for this deletes the text only after you have already deleted it yourself and punched in your new text. What I'm loooking for is a way to read the focus of the control.

Here's the stripped down basics of what I currently have.

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $input[0] To $input[UBound($input) - 1]
            GUICtrlSetData($nMsg, "")
            GUICtrlGetState(
    EndSwitch
WEnd

You need to do something like this

GUICreate(...............

Global $hEditFocus = 0;no edit has focus. NB dealing with handles

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND");or some function name
GUISetState()

While 1
    $Msg = GUIGetMsg()
    ;etc
WEnd


Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)

    Switch $iCode

    Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
    $hEditFocus = 0
    Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
    $hEditFocus = $hWndFrom

    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc ;==>_LoWord
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You need to do something like this

GUICreate(...............

Global $hEditFocus = 0;no edit has focus. NB dealing with handles

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND");or some function name
GUISetState()

While 1
    $Msg = GUIGetMsg()
    ;etc
WEnd


Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)

    Switch $iCode

    Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
    $hEditFocus = 0
    Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
    $hEditFocus = $hWndFrom

    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc ;==>_LoWord

Wow! Thanks you, Martin, as always! Lots of new commands in there I've never seen. I probably just spent a good 45 minutes in the help file looking at examples and definitions. I'm starting to understand what you're doing.

;#Region Martin's code section 1 of 2 of 2

#include <WinAPI.au3>
Global $hEditFocus = 0 ;  no edit has focus. NB dealing with handles
;What is the "NB"?
;ans: 
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; or some function name
GUISetState()

;#EndRegion Martin's code section 1 of 2 of 2

So here we are basically defining a function that will run whenever Windows gives us the message $WM_Command?

2nd part: I read up on all the commands you used and asked for clarification on some, if you don't mind. For your convenience I already made a new line ;ans: for you to answer on

;#Region Martin's code section 2 of 2

; I added from here...
$hEdit = WinGetHandle($title)
; to here...

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ;what are the last two? I understand they are the "first and second parameter messages" as hex values, but what exactly does that mean? I think the first is for if it has focus or not?
    ; What do the two last parameters mean?
    ; ans:
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    If Not IsHWnd($hEdit) Then $hWndEdit = GUICtrlGetHandle($hEdit) ; so we're checking if $hEdit is a valid window handle,
    ; if not, then making a temporary variable for the window handle. What is $hEdit in the first place, the handle of my GUI?
    ; Do I want to put $hEdit = WinGetHandle($title) to give it the handle of my gui?
    ; Ans:
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam) ; I looked this up, but still don't really understand it's purpose. The "longword" is the 1st par msg from above? Whatever it means, it equals 0 if the contorl doesn't have focus?
    ; Why is this here?
    ; ans:
    $iCode = _WinAPI_HiWord($iwParam) ; same here...
    ; Why is this here?
    ; ans:
    Switch $iCode
        Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
            $hEditFocus = 0
        Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
            $hEditFocus = $hWndFrom
    EndSwitch

    ; so here is where we find out if the control is activated? If $hEditFocus = 0 it means no focus, if it does
    ; have focus it equals "The second message parameter as hex value." What exactly is the second
    ; message? How do I interepret the hex value? Would it be the control that was activated? i.e. $input[1] ?
    ; ans:
    Return $GUI_RUNDEFMSG ; I read up on return and it's starting to make sense. In this case Return would equal either 0 or $hWndFrom?
    ;ans:
EndFunc   ;==>_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16) ; for making the long hex value into simpler, understandable number? Yes? No?
    ;ans:
EndFunc   ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF) ; adds 0xFFFF to the bit value? What is the purpose?
    ;ans:
EndFunc   ;==>_LoWord

;#EndRegion Martin's code section 2 of 2

Basic gist: Make a function that runs whenever a new control is highlighted in the GUI. The function determines which control is focused on?

Edited by danielmohr91
Link to comment
Share on other sites

danielmohr91,

First look up WM_COMMAND on msdn, then look up EN_SETFOCUS on msdn.

You will seethat that the EN_SETFOCUS is sent when an edit is given focus. The message contains 2 parameters, wParam and lParam.

EN_SETFOCUS

WPARAM wParam

LPARAM lParam; Parameters

wParam The low-order word specifies the edit control identifier. The high-order word specifies the notification message.

lParam A handle to the edit control.

So you get the low order word of wparam to see what the ID of the edit is. I should have used that and the handle bit I showed was not really a good idea and probably confusing.

But maybe you need to learn about messages first. You also need to learn a bit more about binary arithmetic and boolean operators. Your approach so far is encouraging but don't try to do too much too soon.

;#Region Martin's code section 2 of 2

; I added from here...
;$hEdit = WinGetHandle($title)

;no, the $hEditwas for the handle of an edit, but I have decide to keep to the IDs. So now we use
Global $EditFocus=0
;Maybe you have several
$edit1 = guictrlCreateEdit(...
$edit2 = .......


Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) ;what are the last two? I understand they are the "first and second parameter messages" as hex values, but what exactly does that mean? I think the first is for if it has focus or not?
    ; What do the two last parameters mean?
    ; ans:You cannot tell without looking up what they mean for a particular message. The original writers decide something like, "if we're sending a message to say that X has     
 ;occurred then we'll add B + Q for wParam and use D for lParam and if they want to reply that P then the answer must be Q.


    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit;<-----------we don't need $hWndFrom or $hWWndEdit so ignore them (delete them)
 
    ; if not, then making a temporary variable for the window handle. What is $hEdit in the first place, the handle of my GUI?
    ; Do I want to put $hEdit = WinGetHandle($title) to give it the handle of my gui?
    ; Ans:no, we aren't dealing with the window but an edit control. All controls have handles as well as IDs. Lets use the ID for the edit.
    $hWndFrom = $ilParam; this is the handle of the control which sent the notification, but we will ignore it and use the ID ($iIDfrom)

    $iIDFrom = _WinAPI_LoWord($iwParam) ; I looked this up, but still don't really understand it's purpose. The "longword" is the 1st par msg from above? Whatever it means, it equals 0 if the contorl doesn't have focus?
    ; Why is this here? 

;ANS
;The wParam has 8 bytes. Depending on the message or notification windows will use those bytes in different ways. Fo $EN_SETFOCUS it uses it for 2 
;completely different things. The high order bytes are used for the id number of the control, and the low order bytes are used for the notification reference number.
    ;So if wParam is 0x00090100 it means that the control with ID 9 wants to tell you that it has just received focus because $EV_SETFOCUS is 0x0100.
 
 $iCode = _WinAPI_HiWord($iwParam) ; same here...
    ; Why is this here?
    ; ans: the high word of the $iwParam is the notification code, ie the reason for the message -The text has changed, focus gained/lost etc
    Switch $iCode
        Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
            $EditFocus = 0
        Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
            $EditFocus = $iIDFrom 
    EndSwitch

    ; so here is where we find out if the control is activated? <---Not activated really but receives focus. 
 ;If $EditFocus = 0 it means no focus, if an edit does
    ; have focus it equals the id of the edit which has focus <-correct now but it was the handle 
 
    Return $GUI_RUNDEFMSG ; I read up on return and it's starting to make sense. In this case Return would equal either 0 or $hWndFrom?
    ;ans:If you deal with a message and don't want any further processing done in response to it then you need to return the code relevant for the particular message or notification. Actually I don't think notifications usually have any return code but messages do.
;For example, if you want to paint a control yourself then you handle the message which tells the control to paint, and return whichever value is needed to tell windows that ;that message has been dealt with, otherwise windows will paint it again and destroy what you did.
EndFunc ;==>_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16) ; for making the long hex value into simpler, understandable number? Yes? No?
    ;ans: No it shifts the bits right 16 places so that the highest 16 bits are now in the position of the lowest 16 and the highest 16 are now 0.
 :equivalent to dividing by 2^16 or 16^4
EndFunc ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF) ; adds 0xFFFF to the bit value? What is the purpose?-
    ;No, And not Add so it removes the high order part (0x12345678 AND 0x0000FFFF = 0x00005678)
    ;ans:
EndFunc ;==>_LoWord
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Wow! Thank you so much for explaining this to me. I read the pages on msdn and everything suddenly clicked. Correct me if I'm wrong, but all we're doing is creating a function that runs whenever windows sends a message. If it is either $EN_KILLFOCUS or $EN_SETFOCUS then we get the ID of the control just focused on, or left focus on. I've got the basics up and running, and I actually understand what it's doing now. I've got a minor problem though, when I go to interpret the results. I made a small GUI to help demonstrate the problem. Click around on the different controls, and the ID shows up in the edit box of the GUI. It worked for the input boxes only. If I started typing in the input, highlighted within the input, or clicked on the button, it immediately closed with an error message saying $EditFocus is undeclared. To counter this I added an additional Else argument in the Switch Statement (I commented showing where in the actual code) I can now click on any control without errors, but now I'm only notified when a control has lost focused. What is the correct way to do this?

#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


;~ Create GUI
$title = "GUI"
$GUI = GUICreate($title, 780, 500)
$Button = GUICtrlCreateButton("BUTTON", 50, 50)
$Edit1 = GUICtrlCreateEdit("Windows Messages:" & @CRLF & @CRLF & @CRLF, 300, 50, 200, 400)
$Edit2 = GUICtrlCreateEdit("Last Message:" & @CRLF & @CRLF, 525, 50, 200, 100)
$iMax = 15
Dim $input[$iMax]
For $i = 0 To $iMax - 1
    $input[$i] = GUICtrlCreateInput("HI", 50, 100 + 22 * $i, 209, 20)
    GUICtrlSetData($input[$i], "Name " & $i + 1)
Next
GUISetState()

;~ Defining a few variables
Global $hEditFocus = 0 ;  no edit has focus. NB dealing with handles
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; or some function name
GUISetState()


;~ Main Loop
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $input[0] To $input[UBound($input) - 1]
            TrayTip("Debugging", @ScriptLineNumber, 10)
            ;sleep(500)
    EndSwitch
WEnd


;~ Functions
Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom, $iCode

    $iIDFrom = _WinAPI_LoWord($iwParam)
    ;The wParam has 8 bytes. Depending on the message or notification windows will use those bytes in different ways. For $EN_SETFOCUS it uses it for 2
    ;completely different things. The high order bytes are used for the id number of the control, and the low order bytes are used for the notification
    ;reference number. So if wParam is 0x00090100 it means that the control with ID 9 wants to tell you that it has just received focus because
    ;$EV_SETFOCUS is 0x0100.

    $iCode = _WinAPI_HiWord($iwParam)
    ;the high word of the $iwParam is the notification code, ie the reason for the message -The text has changed, focus gained/lost etc
    Switch $iCode
        Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
            $EditFocus = 0
        Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
            $EditFocus = $iIDFrom
        Case Else ;  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ I ADDED THIS ARGUMENT HERE @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
            $EditFocus = "none"
    EndSwitch
;~  If control has get's focus we get the ID, if it loses focus, zero

    If $EditFocus = Not "none" Then
        $msg1 = GUICtrlRead($Edit1)
        $msg2 = "$iCode = " & $iCode & @CRLF
        $msg4 = "$iwParam = " & $iwParam & @CRLF
        $msg3 = "$EditFocus = " & $EditFocus & @CRLF ; whenever I press the button, or start typing into an input I generate an error - $EditFocus is undeclared.
        ; It's funny becuase as far as I can tell $iwParam and $iCode are still fine, I moved the both a line above this one, and $EditFocus is still the problem.
        ; That leads me to think that the problem is within the...

;~  Switch $iCode
;~      Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
;~          $EditFocus = 0
;~      Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
;~          $EditFocus = $iIDFrom
;~  EndSwitch

        ;       ...section directly above this. I suspected the problem was becuase no focus was given. Now that it looks like the problem is in the switch statement
        ; it appears my suspicions were correct?
        ; The obvious fix was to add an Case Else statement there. Was that the right way to do it? All I care about is whether focus is given or not, so can I
        ; just ignore everything else? I went ahead and added it, but now I'm only getting notified when focus is lost. How would you do this?

        $msg = $msg1 & $msg2 & $msg3 & $msg4 & $ilParam & @CRLF
        GUICtrlSetData($Edit1, $msg & @CRLF)
        GUICtrlSetData($Edit2, $msg2 & $msg3 & $msg4 & $ilParam & @CRLF)
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND


Func _HiWord($x)
    Return BitShift($x, 16) ; for making the long hex value into simpler, understandable number? Yes? No?
    ;ans: No it shifts the bits right 16 places so that the highest 16 bits are now in the position of the lowest 16 and the highest 16 are now 0.
    ;equivalent To dividing by 2 ^ 16 Or 16 ^ 4
    TrayTip("Testing HiWord", @ScriptLineNumber, 10)
    MsgBox(0, "", "Testing HiWord " & @ScriptLineNumber)
EndFunc   ;==>_HiWord


Func _LoWord($x)
    Return BitAND($x, 0xFFFF) ; adds 0xFFFF to the bit value? What is the purpose?-
    ;No, And not Add so it removes the high order part (0x12345678 AND 0x0000FFFF = 0x00005678)
    ;ans:
    TrayTip("Testing LoWord", @ScriptLineNumber, 10)
    MsgBox(0, "", "Testing LoWord " & @ScriptLineNumber)
EndFunc   ;==>_LoWord

EDIT: What are the last two functions for? They are never called in the script. Is it an alternative to the built in _WinAPI_HiWord() and _WinAPI_LoWord() command?

Edited by danielmohr91
Link to comment
Share on other sites

The functions which were not used were just a mistakle of my copy and paste process to get an example.

No time for much explanation now but here is a change to your script which you will be abl eto work out what the differences are.

#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


;~ Create GUI
$title = "GUI"
$GUI = GUICreate($title, 780, 500)
$Button = GUICtrlCreateButton("BUTTON", 50, 50)
$Edit1 = GUICtrlCreateEdit("Windows Messages:" & @CRLF & @CRLF & @CRLF, 300, 50, 200, 400)
$Edit2 = GUICtrlCreateEdit("Last Message:" & @CRLF & @CRLF, 525, 50, 200, 100)
$iMax = 15
Dim $input[$iMax]
For $i = 0 To $iMax - 1
    $input[$i] = GUICtrlCreateInput("HI", 50, 100 + 22 * $i, 209, 20)
    GUICtrlSetData($input[$i], "Name " & $i + 1)
Next
GUISetState()

;~ Defining a few variables
Global $EditFocus = 0 ; no edit has focus. NB dealing with handles
Global $LastEdFocus = 0
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; or some function name
GUISetState()


;~ Main Loop
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $input[0] To $input[UBound($input) - 1]
    TrayTip("Debugging", @ScriptLineNumber, 10)
    ;sleep(500)
    EndSwitch
WEnd


;~ Functions
Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iIDFrom, $iCode

    $iIDFrom = _WinAPI_LoWord($iwParam)
    ;The wParam has 8 bytes. Depending on the message or notification windows will use those bytes in different ways. For $EN_SETFOCUS it uses it for 2
    ;completely different things. The high order bytes are used for the id number of the control, and the low order bytes are used for the notification
    ;reference number. So if wParam is 0x00090100 it means that the control with ID 9 wants to tell you that it has just received focus because
    ;$EV_SETFOCUS is 0x0100.

    $iCode = _WinAPI_HiWord($iwParam)
    ;the high word of the $iwParam is the notification code, ie the reason for the message -The text has changed, focus gained/lost etc
    Switch $iCode
    Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
    $EditFocus = 0
    Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
    $EditFocus = $iIDFrom

    EndSwitch
;~ If control has get's focus we get the ID, if it loses focus, zero

    If $EditFocus <> $LastEdFocus Then
    ;$msg1 = GUICtrlRead($Edit1)
    $msg2 = "$iCode = " & $iCode & @CRLF
    $msg4 = "$iwParam = " & $iwParam & @CRLF
    $msg3 = "$EditFocus = " & $EditFocus & @CRLF ; whenever I press the button, or start typing into an input I generate an error - $EditFocus is undeclared.
    ; It's funny becuase as far as I can tell $iwParam and $iCode are still fine, I moved the both a line above this one, and $EditFocus is still the problem.
    ; That leads me to think that the problem is within the...

;~ Switch $iCode
;~  Case $EN_KILLFOCUS ; Sent when an edit control loses the keyboard focus
;~  $EditFocus = 0
;~  Case $EN_SETFOCUS ; Sent when an edit control receives the keyboard focus
;~  $EditFocus = $iIDFrom
;~ EndSwitch

    ;   ...section directly above this. I suspected the problem was becuase no focus was given. Now that it looks like the problem is in the switch statement
    ; it appears my suspicions were correct?
    ; The obvious fix was to add an Case Else statement there. Was that the right way to do it? All I care about is whether focus is given or not, so can I
    ; just ignore everything else? I went ahead and added it, but now I'm only getting notified when focus is lost. How would you do this?

    $msg = $msg2 & $msg3 & $msg4 & $ilParam & @CRLF
    GUICtrlSetData($Edit1, $msg & @CRLF,1)
    GUICtrlSetData($Edit2, $msg3 & $msg4 & $ilParam & @CRLF,1)
        $LastEdFocus = $EditFocus
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_COMMAND

Your "else" idea was not so good because what if there is a notification from an edit which has nothing to do with focus? Then you would set no edit to have focus which would not always be true, For example, every time the text in an edit is changed it sends $EN_CHANGE notification.

Instead of replacing all the text in an edit, which results in the cursor going back to the top, I added the text to the existing text.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...