Jump to content

Quick One! $msg = {enter} Press Button


litlmike
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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)?

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.

Link to comment
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!
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...