Sign in to follow this  
Followers 0
inm101

HotKeySet while within specific control?

5 posts in this topic

Is it possible to do a "HotKeySet" while the cursor is in a specific AutoIT Edit box?

For example, I want "Enter" to act as "Tab" when the user hits "Enter" while their cursor is in the "Edit1" AutoIT control.

Thanks!

Share this post


Link to post
Share on other sites



i would say:

activate your gui,

then:

Opt("MouseCoordMode", 0)        ;1=absolute, 0=relative, 2=client
$pos = MouseGetPos()
if $pos[0] = VALUE and $pos[1] = VALUE then
HotKeySet ( "key" [, "function"] )
...
endif

instead of VALUE put numeric coordinates of your "edit1"

Share this post


Link to post
Share on other sites

You mean an autoit made GUI right? If so you can use GUISetAccelerators. I've used it in programs to move from one edit box to another (to complete a form) in the direction and way I wanted.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Is it possible to do a "HotKeySet" while the cursor is in a specific AutoIT Edit box?

For example, I want "Enter" to act as "Tab" when the user hits "Enter" while their cursor is in the "Edit1" AutoIT control.

Thanks!

You might check ControlGetFocus() on the active window and only when that matches the handle of your control, activate the hot key, else disable that hot key. Be sure to check your state in the loop so you only activate once when the control becomes active, and disable once when it loses focus.

Demo:

#include <GUIConstantsEx.au3>
#include <Date.au3>

Global $hGUI, $ctrlEdit_1, $hEdit_1, $iMsg, $f_HotKeyEnabled = False
$hGUI = GUICreate("Test", 300, 300)
$ctrlEdit_1 = GUICtrlCreateEdit("Hit 't' to test..." & @CRLF, 20, 20, 260, 260)
$hEdit_1 = ControlGetHandle($hGUI, "", $ctrlEdit_1)
GUISetState()

While 1
    $iMsg = GUIGetMsg()
    If $iMsg = $GUI_EVENT_CLOSE Then
        Exit
    Else
        If WinActive($hGUI) And (ControlGetHandle($hGUI, "", ControlGetFocus($hGUI, "")) = $hEdit_1) Then
            If Not $f_HotKeyEnabled Then
                $f_HotKeyEnabled = True
                HotKeySet("t", "_HotKeyFunc")
                ControlSetText($hGUI, "", $hEdit_1, ControlGetText($hGUI, "", $hEdit_1) & "Enabled hotkey: " & _NowCalc() & @CRLF)
            EndIf
        Else
            If $f_HotKeyEnabled Then
                $f_HotKeyEnabled = False
                HotKeySet("t")
                ControlSetText($hGUI, "", $hEdit_1, ControlGetText($hGUI, "", $hEdit_1) & "Disabled hotktey: " & _NowCalc() & @CRLF)
            EndIf
        EndIf
    EndIf
WEnd

Func _HotKeyFunc()
    ControlSetText($hGUI, "", $hEdit_1, ControlGetText($hGUI, "", $hEdit_1) & "Hot T! " & _NowCalc() & @CRLF)
EndFunc   ;==>_HotKeyFunc

:D


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

Share this post


Link to post
Share on other sites

You mean an autoit made GUI right?

Yes, I mean an AutoIT GUI.

Thank you all for your suggestions.

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