Jump to content
Sign in to follow this  
Spiff59

Smart tabbing/focus

Recommended Posts

Spiff59

To simplify, let's say:

I have a GUI with two input controls, and a button control.

I'd like the user to be able to bang on the TAB key all day long and as long as the active input control contained no data, the script would simply toggle focus to the other input control (ignoring the button). If the input control contains data when the TAB key is pressed, focus would jump to the button.

I'm guessing something like: Enable WM_NOTIFY to capture events, then setting WM_NOTIFY to test if the event was from either of the input controls, testing if the event was a keystroke, testing if that keystroke was a TAB key, then checking and assigning focus depending on the result of a GUICtrlRead.

I might also find it useful to have the ENTER key, when pressed on an input containing data, actually execute the same function as if the button had been tabbed to, and then pressed. I'm guessing just add another trap in the switch/case list that will process the ENTER key.

Am I on the right track?

Rather than recreate the wheel, has anyone seen any source or an example that'll save me having to piece this together from scratch???

2.6 tons of thanks.

Share this post


Link to post
Share on other sites
wraithdu

You'll have to trap the button's WM_COMMAND -> BN_SETFOCUS notification and test your input controls. If they're empty, reset focus to the inputs.

Use $BS_DEFPUSHBUTTON style to set the button to trigger on ENTER. You'll then test in your function whether the inputs are empty or not, and reset focus accordingly.

Edited by wraithdu

Share this post


Link to post
Share on other sites
Spiff59

You'll have to trap the button's WM_COMMAND -> BN_SETFOCUS notification and test your input controls. If they're empty, reset focus to the inputs.

Use $BS_DEFPUSHBUTTON style to set the button to trigger on ENTER. You'll then test in your function whether the inputs are empty or not, and reset focus accordingly.

Makes perfect sense! That would allow me to handle focus changes resulting from mouse clicks as well, if I find a requirement to do so.

Thank you, Sir (or madam).

Edited by Spiff59

Share this post


Link to post
Share on other sites
the123punch

Makes perfect sense! That would allow me to handle focus changes resulting from mouse clicks as well, if I find a requirement to do so.

Thank you, Sir (or madam).

Hi Spiff59,

Can you please elaborate on what you did here? I am a newb to AutoIt and have designed a GUI in which I would like to catch the event when the focus is lost from an input box. Almost the same principle as you but it is with an input box that I would like to handle focus changes.

Can you help me with a concrete example of what you did please?

Your help would be greatly appreciated.

the123punch

Share this post


Link to post
Share on other sites
rasim

Hi Spiff59,

Can you please elaborate on what you did here? I am a newb to AutoIt and have designed a GUI in which I would like to catch the event when the focus is lost from an input box. Almost the same principle as you but it is with an input box that I would like to handle focus changes.

Can you help me with a concrete example of what you did please?

Your help would be greatly appreciated.

the123punch

Example:

#include <GuiConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>

$hGui = GUICreate("Test GUI", 300, 200)

$hInput = GUICtrlCreateInput("", 50, 50, 200, 20)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

While GUIGetMsg() <> -3
WEnd

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    
    Local $IdFrom = BitAnd($wParam, 0x0000FFFF)
    Local $iCode = BitShift($wParam, 16)
    
    Switch $IdFrom
        Case $hInput
            Switch $iCode
                Case $EN_SETFOCUS
                    ConsoleWrite("!> Input focused" & @LF)
                Case $EN_KILLFOCUS
                    ConsoleWrite("!> Input lose focuse" & @LF)
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc

Share this post


Link to post
Share on other sites
the123punch

Hi Rasim,

This is great as I said in my previous post on the other topic. It is working great thanks a lot.

Is it possible though to explain me what all these parameters are ? like "WM_COMMAND($hWnd, $Msg, $wParam, $lParam)", or if you can point me to the right documentation that would be awesome.

Thanks again.

the123punch

Share this post


Link to post
Share on other sites
wraithdu

See the GuiRegisterMsg() function in the helpfile.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.