brett Posted May 15, 2004 Posted May 15, 2004 i saw this as an example for the GUI, but can't find it anywhere. -Brett
Josbe Posted May 15, 2004 Posted May 15, 2004 Brett, every function has a example below. Generally, the examples are simples. For easy understanding."Hello World" example, is a way to mention a script for start to learn. (If you sayed for this post) AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta
scriptkitty Posted May 15, 2004 Posted May 15, 2004 ; 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.
Administrators Jon Posted May 15, 2004 Administrators Posted May 15, 2004 MsgBox(0, "", "Hello world") Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Administrators Jon Posted May 15, 2004 Administrators Posted May 15, 2004 ; 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)? Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Valik Posted May 15, 2004 Posted May 15, 2004 (edited) 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 May 15, 2004 by Valik
Administrators Jon Posted May 15, 2004 Administrators Posted May 15, 2004 (edited) 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 May 15, 2004 by Jon Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Valik Posted May 15, 2004 Posted May 15, 2004 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.
Administrators Jon Posted May 15, 2004 Administrators Posted May 15, 2004 WinXP SP1. I just get a "ding" noise. Tab doesn't work either. I also tried the previous unstable just in case my new one was broken... Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
scriptkitty Posted May 15, 2004 Posted May 15, 2004 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.
CyberSlug Posted May 15, 2004 Posted May 15, 2004 WinXP SP1.I just get a "ding" noise. Tab doesn't work either. I also tried the previous unstable just in case my new one was broken... Jon, take a look at this post for some info.... Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Administrators Jon Posted May 15, 2004 Administrators Posted May 15, 2004 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.. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Administrators Jon Posted May 15, 2004 Administrators Posted May 15, 2004 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... Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Valik Posted May 15, 2004 Posted May 15, 2004 I get the same behavior as Jon now. I must of tested with the orginal snippet posted, as my modified message pump version doesn't work.
Administrators Jon Posted May 15, 2004 Administrators Posted May 15, 2004 If I change GuiMsg(0) to GuiMsg() the tab/OK works. I don;t know enough about GuiMsg to understand the difference Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Valik Posted May 15, 2004 Posted May 15, 2004 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.
brett Posted May 15, 2004 Author Posted May 15, 2004 why will this not work? i want to press enter to finish the gui, like jon said. $nOk = GUISetControl ("button", "&Start", 20,200) -Brett
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now