Sign in to follow this  
Followers 0
qwert

How to acheive dual-mode entry?

5 posts in this topic

I need to be able to enter characters into an input field by either clicking a button on the screen -- an "X" in this example -- or by pressing a character on the keyboard. The field needs to accept several characters per entry and allow the keyboard and button to be used interchangeably. The problem is that the first click of the button method deactivates the field for keyboard input.

;   Field entry from button action blocks subsequent keyboard input
;
#include <GUIConstants.au3>

GUICreate("Example", 200, 177, -1, 240, $WS_SIZEBOX + $WS_SYSMENU)

GUICtrlCreatePic(@Systemdir & "\oobe\images\mslogo.jpg", -1, -1, 200, 50)
GUICtrlSetState(-1, $GUI_DISABLE)

$ctrlInput = GUICtrlCreateInput("", 20, 60, 160, 30, $ES_RIGHT)
GUICtrlSetFont($ctrlInput, 16, 600)

$Graphic1 = GUICtrlCreateGraphic(33, 14, 100, 30, $SS_NOTIFY + $SS_WHITEFRAME)
GUICtrlSetTip(-1, "Grahic Button")

$clear = GUICtrlCreateButton("Clear", 50, 110, 40, 20)

GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND")
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $clear
            GUICtrlSetData( $ctrlInput, "" )
            ControlFocus("", "", $ctrlInput )  ; <<<<< this works to enable keyboard entry
        EndSwitch
WEnd

Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iNotifyCode = BitShift($wParam, 16), $iID = BitAnd($wParam, 0x0000FFFF)
    If $iID = $Graphic1 Then
        Switch $iNotifyCode
            Case 0, 1; STN_CLICKED, STN_DBLCLK
                GUICtrlSetData( $ctrlInput, GUICtrlRead( $ctrlInput )  & "X" )
;               ControlFocus("", "", $ctrlInput )             ; <<<<< this didn't work! 
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

I was able to add a ControlFocus to the action for the Clear button to reactivate the field after button input -- but adding it to the button process, itself, didn't work (gave a strange result where the field contents highlighted every other button click).

How can I ensure that the field will accept keyboard entry following a button-based entry? Also, can someone explain where the highlighting came from and why?

Thanks in advance for any help with this.

Share this post


Link to post
Share on other sites



This work fine for me :) It is OK ?

;   Field entry from button action blocks subsequent keyboard input
;
#include <GUIConstants.au3>

GUICreate("Example", 200, 177, -1, 240, $WS_SIZEBOX + $WS_SYSMENU)

GUICtrlCreatePic(@Systemdir & "\oobe\images\mslogo.jpg", -1, -1, 200, 50)
GUICtrlSetState(-1, $GUI_DISABLE)

$ctrlInput = GUICtrlCreateInput("", 20, 60, 160, 30, $ES_RIGHT)
GUICtrlSetFont($ctrlInput, 16, 600)

$Graphic1 = GUICtrlCreateGraphic(33, 14, 100, 30, $SS_NOTIFY + $SS_WHITEFRAME)
GUICtrlSetTip(-1, "Grahic Button")

$clear = GUICtrlCreateButton("Clear", 50, 110, 40, 20)

GUIRegisterMsg($WM_COMMAND, "On_WM_COMMAND")
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $clear
            GUICtrlSetData( $ctrlInput, "" )
            ControlFocus("", "", $ctrlInput ) ; <<<<< this works to enable keyboard entry
        EndSwitch
WEnd

Func On_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iNotifyCode = BitShift($wParam, 16), $iID = BitAnd($wParam, 0x0000FFFF)
    If $iID = $Graphic1 Then
        Switch $iNotifyCode
            Case 0, 1; STN_CLICKED, STN_DBLCLK
                GUICtrlSetData( $ctrlInput, GUICtrlRead( $ctrlInput )  & "X" )
GUICtrlSetState($ctrlInput,$GUI_FOCUS)
                Send("{RIGHT}")
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites

It is OK ?

GUICtrlSetState($ctrlInput,$GUI_FOCUS)

Send("{RIGHT}")

Almost. Adding the two steps (above) took care of activating the field. But now the field has a slight flash effect when clicking in several characters. I'm sure this is because the field is already highlighted when focus is added -- and then the Send clears the highlight.

So the question is: what is causing the highlight in the first place? Getting rid of it would make your solution perfect.

Thanks for the response.

Share this post


Link to post
Share on other sites

Hmmmm, try change :

GUICtrlSetState($ctrlInput,$GUI_FOCUS)
 Send("{RIGHT}")

To:

if GUICtrlGetState($ctrlInput)<>$GUI_FOCUS then 
GUICtrlSetState($ctrlInput,$GUI_FOCUS)
                Send("{RIGHT}")
                endif

Better ? I now that it is not perfect but i dont have any better ideas in this moment :)


Share this post


Link to post
Share on other sites

I couldn't see a difference, but thanks for trying.

Maybe someone can suggest a different approach that avoids the highlighting altogether. It's the part of this that I still don't understand.

Share this post


Link to post
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
Sign in to follow this  
Followers 0