computergroove Posted April 6, 2009 Share Posted April 6, 2009 I am working on a program that generates a gui window in the upper left corner of the screen and in conjunction with Dragon Natural Speaking, I want to be able to say something and have my program execute it. I have come up with a starting point of what I want to be able to do: expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("", 200, 20, 0, 0); creats a GUI window (Width, Height, Left, Top,) $edit_field = GUICtrlCreateInput("", 0, 0, 0, 0); creats a blank textbox in the GUI window $btn_test = GUICtrlCreateButton("Submit", 308, 52, 75, 21, 0); creates a button labeled Submit in the GUI window GUISetState(@SW_SHOW); shows the GUI window? Found reference to @SW_HIDE #EndRegion ### START Koda GUI section ### Form= Func Wait_for_user_input() While 1; loop get user input WEnd EndFunc While 1 $user_input = GUIGetMsg(); get input from the user and declare the data as $user_input Switch $user_input Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ; EndFunc ; search for and scan database.txt for validity Local $f_in = @ScriptDir & "\database.txt"; $fh_in = FileOpen($f_in, 0) ; Check if file opened for reading OK If $fh_in = -1 Then MsgBox(0, "Error 1", "Can't find database.txt.") exit; EndIf While 1 $line = FileReadLine($fh_in) If @error = -1 Then ExitLoop If StringInStr($line, ";") > 0 Then ConsoleWrite($line & @CRLF); EndIf WEnd FileClose($fh_in) 2 questions off the bat. 1. Is there a way to remove the title bar of a gui window? I just want to see a text input box at the top left corner of the screen. 2. I want to type things in the box with dragon natural speaking by saying commands so my problem becomes when to "hit enter". Is there a function in autoit that will read what is in the text box and compare it to a database and execute code without having to hit enter? If so can it compare it to a database of items and if it doesn't match anything can it erase the text in the text box? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
FreeFry Posted April 6, 2009 Share Posted April 6, 2009 (edited) You can create a title-less window by making it a popup window, an example which also removes it from the task bar:#include <GUIConstants.au3> #include <WindowsConstants.au3> GUICreate("Custom GUI", @DesktopWidth/2 , @DesktopHeight/2, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) GUISetBkColor(0xff5050) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSEBut no, something that reads an inputbox, and compares it towards a database is nothing that is native in autoit(you'll have to code the comparison procedure yourself).You'd need an input(GUICtrlCreateInput), and use GuiCtrlRead to read whatever is in the box, and GuiCtrlSetData to clear it. Edit: Removed unnecessary code from example. Edited April 6, 2009 by FreeFry Link to comment Share on other sites More sharing options...
computergroove Posted April 7, 2009 Author Share Posted April 7, 2009 Is there an example of this being done? One of my concerns of doing this is performance of the PC while the program is running. Is there a way to use GUICtrlRead without it destroying the available resources? In other words is there a way for the program to only check and compare to a database if something is in the box? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Hawkwing Posted April 8, 2009 Share Posted April 8, 2009 Maybe something like this? expandcollapse popup#include<guiconstants.au3> #include<file.au3> Opt("guioneventmode", 1) $gui = GUICreate("", 200, 20, 0, 0) GUISetOnEvent($GUI_EVENT_CLOSE, "guievent", $gui) $input = GUICtrlCreateInput("", 0, 0, 0, 0) GUISetState(@SW_SHOW) wait() Func wait() While GUICtrlRead($input) = "" Sleep(500) WEnd checkdatabase() EndFunc Func checkdatabase() $file = FileOpen(@ScriptDir & "\database.txt", 0) While GUICtrlRead($input) = Not "" For $i = 1 To _FileCountLines(@ScriptDir & "\database.txt") If GUICtrlRead($input) = FileReadLine($file, $i) Then whatevertheheckfunctionyouwant() GUICtrlSetData($input, "") EndIf Next WEnd FileClose(@ScriptDir & "\database.txt") wait() EndFunc Func guievent() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE Exit EndSwitch EndFunc Func whatevertheheckfunctionyouwant() EndFunc The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
FreeFry Posted April 8, 2009 Share Posted April 8, 2009 (edited) Why not just something like this:expandcollapse popup#include <GUIConstantsEx.au3> Dim $aDatabase[3][2] = [["Hello", "_Output('Hello There')"], ["Calc", "Run('Calc.exe')"], ["Quit", "WinClose($iGui)"]]; Example database of commands, and what they do. Dim $iGUI = GUICreate("Example", 300, 100) GUICtrlCreateLabel("Enter command:", 5, 5) Dim $iInput = GUICtrlCreateInput("", 5, 25) Dim $iStatusBar = GUICtrlCreateLabel("Status: Ready", 1, 85, 300); A neat status bar :) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If GUICtrlRead($iInput) <> "" Then _HandleInput(); Only check the inputbar if there's something to check WEnd Func _HandleInput() Local $svInput = GUICtrlRead($iInput) ;~ $svInput = StringLower($svInput); Uncomment to make the commands non-cAsE specific For $i = 0 To UBound($aDatabase)-1 If $svInput == $aDatabase[$i][0] Then GUICtrlSetData($iInput, "") GUICtrlSetData($iStatusBar, "Status: Running command: " & $aDatabase[$i][1]) Sleep(1500); Wait some, for the examples sake... :) Execute($aDatabase[$i][1]) Return EndIf Next GUICtrlSetData($iStatusBar, "Status: Invalid command entered") EndFunc Func _Output($svString); Example function GUICtrlSetData($iStatusBar, $svString) EndFuncEdit: Whops forgot a constant in there. Edited April 8, 2009 by FreeFry Link to comment Share on other sites More sharing options...
Hawkwing Posted April 8, 2009 Share Posted April 8, 2009 I didn't think that computergroove wanted to have an array in database.txt. I was thinking about using switch...endswitch to do the different commands. Using an array would probably be better though. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Hawkwing Posted April 9, 2009 Share Posted April 9, 2009 (edited) Here you go. I even made a gui so you can edit the array. expandcollapse popup#include<guiconstants.au3> #include<guilistview.au3> Local $editcommandgui, $command, $action, $listview, $editgui, $Edit, $input, $gui $array = IniReadSection(@ScriptDir & "\database.txt", "Commands") Opt("guioneventmode", 1) Opt("traymenumode", 1) Opt("trayoneventmode", 1) TrayCreateItem("Enter Commands") TrayItemSetOnEvent(-1, "gui") TrayCreateItem("Edit Commands") TrayItemSetOnEvent(-1, "editcommands") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "end") gui() Func gui() If WinExists("Enter Commands", "") Then WinActivate("Enter Commands", "") Return EndIf $gui = GUICreate("Enter Commands", 200, 20, 0, 0) GUISetOnEvent($GUI_EVENT_CLOSE, "guievent", $gui) $input = GUICtrlCreateInput("", 0, 0, 0, 0) GUISetState(@SW_SHOW) EndFunc wait() Func wait() While GUICtrlRead($input) = "" Sleep(500) WEnd checkdatabase() EndFunc Func checkdatabase() $array = IniReadSection(@ScriptDir & "\database.txt", "Commands") While GUICtrlRead($input) = Not "" For $i = 1 To UBound($array)-1 If GUICtrlRead($input) = $array[$i][0] Then GUICtrlSetData($input, "") Execute($array[$i][1]) EndIf Next WEnd wait() EndFunc Func guievent() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE If WinActive("Enter Commands") Then GUIDelete($gui) Else GUIDelete($editgui) EndIf EndSwitch EndFunc Func editcommands() If WinExists("Edit Commands", "") Then WinActivate("Edit Commands", "") Return EndIf $editgui = GUICreate("Edit Commands", 220, 386) GUISetOnEvent($GUI_EVENT_CLOSE, "guievent", $editgui) $listview = GUICtrlCreateListView("Command|Action ", 5, 5, 210, 320) $buttonnew = GUICtrlCreateButton("New Command", 5, 330, 210, 23) GUICtrlSetOnEvent($buttonnew, "newcommand") $buttonedit = GUICtrlCreateButton("Edit Command", 5, 358, 210, 23) GUICtrlSetOnEvent($buttonedit, "editcommand") For $i = 1 To UBound($array)-1 GUICtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1], $listview) Next GUISetState(@SW_SHOW, $editgui) EndFunc Func newcommand() $newcommandgui = GUICreate("New Command", 150, 141) GUICtrlCreateLabel("Command", 5, 5) $command = GUICtrlCreateInput("", 5, 20, 140, 20) GUICtrlCreateLabel("Action", 5, 45) $action = GUICtrlCreateInput("", 5, 60, 140, 20) GUICtrlCreateButton("Create Command", 5, 85, 140, 23) GUICtrlSetOnEvent(-1, "commandcomplete") GUICtrlCreateButton("Cancel", 5, 113, 140, 23) GUICtrlSetOnEvent(-1, "cancel") GUISetState() EndFunc Func commandcomplete() $Ubound = UBound($array) ReDim $array[$Ubound+1][2] $array[$Ubound][0] = GUICtrlRead($command) $array[$Ubound][1] = GUICtrlRead($action) _GUICtrlListView_DeleteAllItems($listview) _ArraySort($array, 0, 1) For $i = 1 To UBound($array)-1 GUICtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1], $listview) Next IniWriteSection(@ScriptDir & "\database.txt", "Commands", $array) GUIDelete(@GUI_WinHandle) EndFunc Func editcommand() $Selected = GUICtrlRead($listview) $Edit = GUICtrlRead($Selected) $Edit = StringSplit($Edit, "|") If Not IsArray($Edit) Then Return EndIf $editcommandgui = GUICreate("Edit Command", 150, 169) GUICtrlCreateLabel("Command", 5, 5) $ShortCut = GUICtrlCreateInput($Edit[1], 5, 20, 140, 20) GUICtrlCreateLabel("Action", 5, 45) $Text = GUICtrlCreateInput($Edit[2], 5, 60, 140, 20) GUICtrlCreateButton("Complete Edit", 5, 85, 140, 23) GUICtrlSetOnEvent(-1, "commandcomplete") GUICtrlCreateButton("Delete", 5, 113, 140, 23) GUICtrlSetOnEvent(-1, "deletecommand") GUICtrlCreateButton("Cancel", 5, 141, 140, 23) GUICtrlSetOnEvent(-1, "cancel") For $i = 1 To UBound($array)-1 If ($array[$i][0] = $Edit[1]) And ($array[$i][1] = $Edit[2]) Then _ArrayDelete($array, $i) ExitLoop EndIf Next GUISetState() EndFunc Func deletecommand() GUIDelete($editcommandgui) GUISetState(@SW_ENABLE, $editgui) GUICtrlSetState($listview, $GUI_FOCUS) For $i = 1 To UBound($array)-1 If($array[$i][0] = $Edit[1]) And ($array[$i][1] = $Edit[2]) Then _ArrayDelete($array, $i) ExitLoop EndIf Next _GUICtrlListView_DeleteAllItems($listview) _ArraySort($array) For $i = 1 To UBound($array)-1 GUICtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1], $listview) Next IniWriteSection(@ScriptDir & "\database.txt", "Commands", $array) EndFunc Func cancel() GUIDelete(@GUI_WinHandle) GUISetState(@SW_ENABLE, $editcommandgui) GUICtrlSetState($listview, $GUI_FOCUS) EndFunc Func end() Exit EndFunc Edited April 9, 2009 by pigeek The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
FreeFry Posted April 9, 2009 Share Posted April 9, 2009 He could parse his database into an array, his database could be a .ini file or any other format he likes, he just has to do loading from the database into the array himself. My $aDatabase array was just an example. Link to comment Share on other sites More sharing options...
computergroove Posted May 7, 2009 Author Share Posted May 7, 2009 (edited) Here you go. I even made a gui so you can edit the array. expandcollapse popup#include<guiconstants.au3> #include<guilistview.au3> Local $editcommandgui, $command, $action, $listview, $editgui, $Edit, $input, $gui $array = IniReadSection(@ScriptDir & "\database.txt", "Commands") Opt("guioneventmode", 1) Opt("traymenumode", 1) Opt("trayoneventmode", 1) TrayCreateItem("Enter Commands") TrayItemSetOnEvent(-1, "gui") TrayCreateItem("Edit Commands") TrayItemSetOnEvent(-1, "editcommands") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "end") gui() Func gui() If WinExists("Enter Commands", "") Then WinActivate("Enter Commands", "") Return EndIf $gui = GUICreate("Enter Commands", 200, 20, 0, 0) GUISetOnEvent($GUI_EVENT_CLOSE, "guievent", $gui) $input = GUICtrlCreateInput("", 0, 0, 0, 0) GUISetState(@SW_SHOW) EndFunc wait() Func wait() While GUICtrlRead($input) = "" Sleep(500) WEnd checkdatabase() EndFunc Func checkdatabase() $array = IniReadSection(@ScriptDir & "\database.txt", "Commands") While GUICtrlRead($input) = Not "" For $i = 1 To UBound($array)-1 If GUICtrlRead($input) = $array[$i][0] Then GUICtrlSetData($input, "") Execute($array[$i][1]) EndIf Next WEnd wait() EndFunc Func guievent() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE If WinActive("Enter Commands") Then GUIDelete($gui) Else GUIDelete($editgui) EndIf EndSwitch EndFunc Func editcommands() If WinExists("Edit Commands", "") Then WinActivate("Edit Commands", "") Return EndIf $editgui = GUICreate("Edit Commands", 220, 386) GUISetOnEvent($GUI_EVENT_CLOSE, "guievent", $editgui) $listview = GUICtrlCreateListView("Command|Action ", 5, 5, 210, 320) $buttonnew = GUICtrlCreateButton("New Command", 5, 330, 210, 23) GUICtrlSetOnEvent($buttonnew, "newcommand") $buttonedit = GUICtrlCreateButton("Edit Command", 5, 358, 210, 23) GUICtrlSetOnEvent($buttonedit, "editcommand") For $i = 1 To UBound($array)-1 GUICtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1], $listview) Next GUISetState(@SW_SHOW, $editgui) EndFunc Func newcommand() $newcommandgui = GUICreate("New Command", 150, 141) GUICtrlCreateLabel("Command", 5, 5) $command = GUICtrlCreateInput("", 5, 20, 140, 20) GUICtrlCreateLabel("Action", 5, 45) $action = GUICtrlCreateInput("", 5, 60, 140, 20) GUICtrlCreateButton("Create Command", 5, 85, 140, 23) GUICtrlSetOnEvent(-1, "commandcomplete") GUICtrlCreateButton("Cancel", 5, 113, 140, 23) GUICtrlSetOnEvent(-1, "cancel") GUISetState() EndFunc Func commandcomplete() $Ubound = UBound($array) ReDim $array[$Ubound+1][2] $array[$Ubound][0] = GUICtrlRead($command) $array[$Ubound][1] = GUICtrlRead($action) _GUICtrlListView_DeleteAllItems($listview) _ArraySort($array, 0, 1) For $i = 1 To UBound($array)-1 GUICtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1], $listview) Next IniWriteSection(@ScriptDir & "\database.txt", "Commands", $array) GUIDelete(@GUI_WinHandle) EndFunc Func editcommand() $Selected = GUICtrlRead($listview) $Edit = GUICtrlRead($Selected) $Edit = StringSplit($Edit, "|") If Not IsArray($Edit) Then Return EndIf $editcommandgui = GUICreate("Edit Command", 150, 169) GUICtrlCreateLabel("Command", 5, 5) $ShortCut = GUICtrlCreateInput($Edit[1], 5, 20, 140, 20) GUICtrlCreateLabel("Action", 5, 45) $Text = GUICtrlCreateInput($Edit[2], 5, 60, 140, 20) GUICtrlCreateButton("Complete Edit", 5, 85, 140, 23) GUICtrlSetOnEvent(-1, "commandcomplete") GUICtrlCreateButton("Delete", 5, 113, 140, 23) GUICtrlSetOnEvent(-1, "deletecommand") GUICtrlCreateButton("Cancel", 5, 141, 140, 23) GUICtrlSetOnEvent(-1, "cancel") For $i = 1 To UBound($array)-1 If ($array[$i][0] = $Edit[1]) And ($array[$i][1] = $Edit[2]) Then _ArrayDelete($array, $i) ExitLoop EndIf Next GUISetState() EndFunc Func deletecommand() GUIDelete($editcommandgui) GUISetState(@SW_ENABLE, $editgui) GUICtrlSetState($listview, $GUI_FOCUS) For $i = 1 To UBound($array)-1 If($array[$i][0] = $Edit[1]) And ($array[$i][1] = $Edit[2]) Then _ArrayDelete($array, $i) ExitLoop EndIf Next _GUICtrlListView_DeleteAllItems($listview) _ArraySort($array) For $i = 1 To UBound($array)-1 GUICtrlCreateListViewItem($array[$i][0] & "|" & $array[$i][1], $listview) Next IniWriteSection(@ScriptDir & "\database.txt", "Commands", $array) EndFunc Func cancel() GUIDelete(@GUI_WinHandle) GUISetState(@SW_ENABLE, $editcommandgui) GUICtrlSetState($listview, $GUI_FOCUS) EndFunc Func end() Exit EndFunc when I compile and run this and I input a command I cannot get it to reset to a blank text box. I hate to ask this but can you comment this program? Also I am having trouble trying to decide if I should make a function within the program and call it from the build in command editor or write the whole function in database.txt. I am leaning towards making the function within the program and calling it from database.txt. Could someone show me what the command in databse.txt should look like to properly call the function within the program? Edited May 7, 2009 by computergroove Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
computergroove Posted May 7, 2009 Author Share Posted May 7, 2009 (edited) For instance I want to use this with Itunes 8 to lets say increase the volume. I want the program to make the active window I tunes and hit the key combination CTRL + UP. so I can make the function: func ItunesVolumeUp() If Winactive("itunes.exe") Winactivate("Itunes") Else Run ("Itunes.exe") Winwaitactive("Itunes") endif Send("{ALTDOWN}{+}{ALTUP}") endfunc Would I put "Call ItunesVolumeUp()" in the command gui? Edited May 8, 2009 by computergroove Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
computergroove Posted May 8, 2009 Author Share Posted May 8, 2009 bump Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
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