ogrish 0 Posted July 3, 2011 Hi, I want to use AutoIt to do the following work. When pressing a predefined key, a menu pops up. Then I click one of the menu item, the correspond code executes. How to do this kind of thing? I can just use AutoIt to do jobs without GUI. Thanks. Share this post Link to post Share on other sites
Xandy 426 Posted July 3, 2011 (edited) #include <Misc.au3>;include for _ispressed function ;#include <guiConstantsex.au3>;include for $gui_event_close value $done= 0 ;$guihandle= GUICreate("Hello world!, wtf am I supposed to do?¿", 420, 200);make a gui window ;$buttonmax= 5 ;dim $button[$buttonmax] ;for $i= 0 to $buttonmax-1 ; $button[$i]= GUICtrlCreateButton("button "&$i, 10, 10+$i*22, 60, 20) ;next ;GUISetState();this code with empty set shows the gui window while $done= 0;main loop ;$msg= GUIGetMsg();get messages from user interaction with gui if _IsPressed("0d") then for $i= 500 to 2000 beep($i, 1) next endif if _IsPressed("1b") then $done= 1 ;if $msg= $gui_event_close then $done= 1;if the user clicks the X button at the top right of the gui window wend press ENTER for beep sound function press ESC for a function to terminate the program Not sure what you want do at be able. Edited July 3, 2011 by songersoft Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Share this post Link to post Share on other sites
monoscout999 10 Posted July 3, 2011 Search for Melba23 Toast in the example section. Forget it, look at this, maybe is useful Share this post Link to post Share on other sites
Melba23 3,458 Posted July 3, 2011 ogrish,Not sure my Toast UDF will help you too much - but this might: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; Set a HotKey to call the menu GUI - here it is Ctrl-Shft-A HotKeySet("^+a", "_Visible") ; Set a HotKey to exit HotKeySet("{ESC}", "On_Exit") Global $aItems[6][3] = [ _ ; Set the 6 to be one more than the number of items you want [5, 0, 0], _ ; Set the 5 to be the number of items ["Item 1", "What you want to do 1", 0], _ ; Just add the items here - [Button title, what you want to do, 0] ["Item 2", "What you want to do 2", 0], _ ["Item 3", "What you want to do 3", 0], _ ["Item 4", "What you want to do 4", 0], _ ["Item 5", "What you want to do 5", 0]] ; Cretae the GUI $hGUI = GUICreate("My PopUp Menu", 200, 20 * $aItems[0][0], -1, -1, BitOR($WS_POPUP, $WS_BORDER)) ; Change the -1, -1 to the coordinates you want ; Create the buttons For $i = 1 To $aItems[0][0] $aItems[$i][2] = GUICtrlCreateButton($aItems[$i][0], 0, (20 * $i) - 20, 200, 20) Next ; Hide the GUI until the Hotkey makes it visible GUISetState(@SW_HIDE) While 1 $iMsg = GUIGetMsg() Switch $iMsg ; Look for the buttons Case $aItems[1][2] To $aItems[$aItems[0][0]][2] ; Hide the GUI again once a button is pressed GUISetState(@SW_HIDE) ; Get the index of the button pressed $iIndex = $iMsg - $aItems[1][2] + 1 ; Display the action - you could use Run here to start an app MsgBox(0, "Action", $aItems[$iIndex][1]) EndSwitch WEnd Func _Visible() ; When the HotKey is pressed make the GUI visible GUISetState(@SW_SHOW) EndFunc Func On_Exit() Exit EndFuncPlease ask if you have any questions. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Share this post Link to post Share on other sites
ProgAndy 88 Posted July 3, 2011 If you want a context-menu like interface, you can use this code: #include<WindowsConstants.au3> #include<GUIMenu.au3> HotKeySet("{F10}", "_Show") $hGUI = GUICreate("", 1, 1, -5, -5, $WS_POPUP, $WS_EX_TOOLWINDOW) $ctlMenu = GUICtrlCreateContextMenu() $ctlMenuAlert = GUICtrlCreateMenuItem("Alert", $ctlMenu) $ctlMenuClose = GUICtrlCreateMenuItem("Exit", $ctlMenu) While 1 Switch GUIGetMsg() Case $ctlMenuAlert MsgBox(0, '', "Message") Case $ctlMenuClose Exit EndSwitch WEnd Func _Show() GUISetState(@SW_SHOW, $hGUI) _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($ctlMenu), $hGUI, -1, -1, 1, 1, 1) GUISetState(@SW_HIDE, $hGUI) EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Share this post Link to post Share on other sites
ogrish 0 Posted July 3, 2011 Thanks everyone! With you guy's help I solved this problem! Thanks! Share this post Link to post Share on other sites