Jump to content

Where Is Helloworld


Recommended Posts

; a basic GUI equivalent to $input= InputBox ("Hello World", "Name?")

GuiCreate ("Hello World") ; start the definition 
    
GuiSetControl ("label", 'Name?', 10,10); add prompt info 
$nInput = GuiSetControl ("input", "", 10,30,200) ; add the input area 
$nOk    = GUISetControl ("button", "OK", 20,70); add the button that will close the GUI 
    
GuiWaitClose (); to display the dialog box 
    
if $nOK= GuiRead () then; to verify if OK was click 
  $input = GuiRead ($nInput); get the type value 
  msgbox(0,"Greeting","Hello " & $input); will display the typed value 
endif

ok, a bit more complex than most hello world starters.

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

  • Administrators

; a basic GUI equivalent to $input= InputBox ("Hello World", "Name?")

GuiCreate ("Hello World"); start the definition 
    
GuiSetControl ("label", 'Name?', 10,10); add prompt info 
$nInput = GuiSetControl ("input", "", 10,30,200); add the input area 
$nOk    = GUISetControl ("button", "OK", 20,70); add the button that will close the GUI 
    
GuiWaitClose (); to display the dialog box 
    
if $nOK= GuiRead () then; to verify if OK was click 
  $input = GuiRead ($nInput); get the type value 
  msgbox(0,"Greeting","Hello " & $input); will display the typed value 
endif

ok, a bit more complex than most hello world starters.

I've not used the gui code yet (too busy implementing...) but how can I modify this script so that pressing enter clicks OK, and can you add an accelerator to OK (Alt+O for example for the label &OK)?
Link to comment
Share on other sites

Jon, simply adding an ampersand before the letter you want the accelerator to be. In that example's case, just make the button text "&Ok".

As for your second request (Well, first, really...), I don't know how to do that short of trapping enter with a hotkey and translating that to what button should be pressed if the GUI has focus or letting it fall back through to any other window. That's not possible with that simple GUI, though. WinWaitClose() is a blocking call like MsgBox() or InputBox() so hotkeys don't work. It would require a polling message pump to implement. Something like this (This is a little buggy with the message box because Enter won't work in it, but it's easy to fix):

Opt("GuiNotifyMode", 1)
GuiCreate ("Hello World"); start the definition 
   
GuiSetControl ("label", 'Name?', 10,10); add prompt info 
$nInput = GuiSetControl ("input", "", 10,30,200); add the input area 
$nOk    = GUISetControl ("button", "&OK", 20,70); add the button that will close the GUI 

GuiShow()

HotKeySet("{ENTER}", "Callback")

While WinExists("Hello World")
    $msg = GuiMsg(0)
    If $msg = -3 Then
        GuiDelete(); Force exit from While loop
    ElseIf $msg = $nOk Then
        $input = GuiRead ($nInput); get the type value 
        msgbox(0,"Greeting","Hello " & $input)
    EndIf
Wend

Func Callback()
    If WinActive("Hello World") Then 
        ControlClick("Hello World", "", "&OK")
    Else
        HotKeySet("{ENTER}")
        Send("{ENTER}")
        HotKeySet("{ENTER}", "Callback")
    EndIf
EndFunc
Edited by Valik
Link to comment
Share on other sites

  • Administrators

Jon, simply adding an ampersand before the letter you want the accelerator to be.  In that example's case, just make the button text "&Ok". 

I tried that and it changed the label but ignored the key press. I'll try again.

Edit: Still no joy.

Edited by Jon
Link to comment
Share on other sites

I tried that and it changed the label but ignored the key press.  I'll try again.

Edit: Still no joy.

An OS thing, perhaps? In that code I posted, I can press Alt+O to activate the okay button.
Link to comment
Share on other sites

works for me:

Opt("GuiNotifyMode", 1)
GuiCreate ("Hello World"); start the definition
 
GuiSetControl ("label", 'Name?', 10,10); add prompt info
$nOk    = GUISetControl ("button", "&OK", 20,70); add the button that will close the GUI
$nInput = GuiSetControl ("input", "", 10,30,200); add the input area

GuiShow()

HotKeySet("{ENTER}", "Callback")

While WinExists("Hello World")
   $msg = GuiMsg(0)
   If $msg = -3 Then
       GuiDelete(); Force exit from While loop
   ElseIf $msg = $nOk Then
       $input = GuiRead ($nInput); get the type value
       GuiDelete(); Force exit from While loop
       msgbox(0,"Greeting","Hello " & $input)
   EndIf
Wend

Func Callback()
   If WinActive("Hello World") Then
       ControlClick("Hello World", "", "&OK")
   Else
       HotKeySet("{ENTER}")
       Send("{ENTER}")
       HotKeySet("{ENTER}", "Callback")
   EndIf
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

  • Administrators

Something really screwy here, if I run it 20 times it will sort of work 5 times and do nothing the other times. Sometimes tab works and sometimes not. Sometimes ALT+O will work, but only if focus is not in the edit field...and then not always..

Link to comment
Share on other sites

  • Administrators

Jon, take a look at this post for some info....

I took the HotKeySet out and I still get it.

This seems to work everytime:

GUICreate("My GUI")
GUISetControl("button", "Boo", 0,50)
GUISetControl("button", "&OK", 100,50)

While GuiMsg () > 0     
  MsgBox(0,"", "OK Clicked",2)
Wend

But the code in this thread doesn't...

Link to comment
Share on other sites

GuiMsg([timeout]) and GuiMsg() block everything until a message is received. GuiMsg(0) polls for new messages, but leaves the thread active. I bet there is some different way going on behind the scenes that is causing these issues with how JP has these various ways of getting messages set up.

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...