Sign in to follow this  
Followers 0
litlmike

Quick One! $msg = {enter} Press Button

8 posts in this topic

I have a GUI. Whenever the user presses enter, I want it to press/click my "Done" button. No matter where the user is focused. How do I do this?

Thanks in advance!

Share this post


Link to post
Share on other sites



you can use the button style called $BS_DEFPUSHBUTTON.


[size=20]My File Upload[/size]Register at my site and upload.

Share this post


Link to post
Share on other sites

well, you could start a function when you're pressing enter

;1.
hotkeyset("{enter}", "start")

while 1
sleep (100)
wend

func start()
msgbox (0, "Start", "Function started")
endfunc

;or 2.
while 1
if _ispressed ("0D") then start()
wend

func start()
msgbox (0, "Start", "Function started")
endfunc

both should work

you can edit the both that they only work if your window is active by:

if winactive("your window title", "") then; do whatever

Share this post


Link to post
Share on other sites

well, you could start a function when you're pressing enter

;1.
hotkeyset("{enter}", "start")

while 1
sleep (100)
wend

func start()
msgbox (0, "Start", "Function started")
endfunc

;or 2.
while 1
if _ispressed ("0D") then start()
wend

func start()
msgbox (0, "Start", "Function started")
endfunc

both should work

you can edit the both that they only work if your window is active by:

if winactive("your window title", "") then; do whatever
You don't get an error with 2 func start()(s)?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites
:), I didn't notice that!!

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Simple example using OnEvent, though GuiGetMsg could be used instead:

#include <GuiConstants.au3>

Opt("GuiOnEventMode", 1)

$GUI = GuiCreate("Example")
GuiSetOnEvent($GUI_EVENT_CLOSE, "quit")
    $input = GuiCtrlCreateInput("input box", 10, 10, 200, 30)
    $button = GuiCtrlCreateButton("Click Here", 10, 60, 100, 40)
    GUICtrlSetOnEvent($button, "simulateClick")
GuiSetState()

While 1
    sleep(100)
    
; Set Enter as hotkey only when our GUI is active
    If WinActive($GUI) Then
        HotKeySet("{Enter}", "simulateClick")
    Else
        HotKeySet("{Enter}")
    EndIf
WEnd

Func simulateClick()
    HotKeySet("{Enter}");good idea to unregister hotkey when MsgBox appears....
    MsgBox(0x1000, "Debug", "Button was 'clicked'")
    HotKeySet("{Enter}", "simulateClick")
EndFunc

Func quit()
    Exit
EndFunc

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

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