meisandy Posted December 3, 2009 Share Posted December 3, 2009 Hi, Basically i've got an input which says "Type text here!". And I want it to delete the text when clicked in, but if the user hasn't inputted anything to default back to the origanal message: "Type text here!". But if thats really to hard or not possible, I would just like it to highlight the message on click! Please Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 3, 2009 Moderators Share Posted December 3, 2009 DjATUit,There is probably a really sexy way to do this using windows messages, but this hobbyist code seems to work: expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $hInput = GUICtrlCreateInput("Type text here!", 10, 10, 250, 20) $hInput_Handle = GUICtrlGetHandle(-1) $hButton = GUICtrlCreateButton("Read", 10, 50, 80, 30) $hLabel = GUICtrlCreateLabel("", 10, 100, 250, 20) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState() $fInput_Flag = False While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton $sText = GUICtrlRead($hInput) Switch $sText Case "", "Type text here!" ; Do nothing Case Else GUICtrlSetData($hLabel, $sText) EndSwitch $fInput_Flag = False GUICtrlSetData($hInput, "Type text here!") EndSwitch $hFocused = _WinAPI_GetFocus() If $hFocused = $hInput_Handle Then If $fInput_Flag = False Then $fInput_Flag = True $iBegin = TimerInit() GUICtrlSetData($hInput, "") Else If GUICtrlRead($hInput) = "" And TimerDiff($iBegin) > 2000 Then $fInput_Flag = False GUICtrlSetData($hInput, "Type text here!") GUICtrlSetState($hButton, $GUI_FOCUS) EndIf EndIf EndIf WEndThe code is pretty self-explanatory - note the use of $fInput_Flag to signal whether the timer is running to reset the text. Obviously you can change the delay by altering the TimerDiff line.As usual, please ask if anything is unclear. 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 3, 2009 Author Share Posted December 3, 2009 So sorry for so reply Thanks so much again I'm having a bit of a problem with flikering though: When I click on the input box "Type text here" flickers and I cannot type anything!? Link to comment Share on other sites More sharing options...
meisandy Posted December 3, 2009 Author Share Posted December 3, 2009 Oh forget that, silly me ive sorted it THANKS AGAIN Melba23! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 3, 2009 Moderators Share Posted December 3, 2009 DjATUit, Does it flicker A.) when you run the code I posted or B.) when you have incorporated it into your script? If A.) - well, it does not flicker for me and I can type in the input without problem! I do not post untested code! If B.) - post the combined code so we can see what is going wrong. 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 3, 2009 Author Share Posted December 3, 2009 Okay me again! Instead of the text reappearing after so long i would like it to reappear when the user clicks of the input box? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 3, 2009 Moderators Share Posted December 3, 2009 DjATUit, To make sure I understand - you want the text to reappear as soon as the focus leaves the input box. If that is the case: #include <GUIConstantsEx.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $hInput = GUICtrlCreateInput("Type text here!", 10, 10, 250, 20) $hInput_Handle = GUICtrlGetHandle(-1) $hButton = GUICtrlCreateButton("Dummy", 10, 50, 80, 30) $hLabel = GUICtrlCreateLabel("", 10, 100, 250, 20) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState() $fInput_Flag = False While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch $hFocused = _WinAPI_GetFocus() If $hFocused = $hInput_Handle Then If $fInput_Flag = False Then $fInput_Flag = True GUICtrlSetData($hInput, "") EndIf Else $fInput_Flag = False GUICtrlSetData($hInput, "Type text here!") EndIf WEnd The button is just there so the focus can go somewhere else. But be careful, if you need to press a button to read the input you will always get the default text as it is reset as soon as you press the button. 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 3, 2009 Author Share Posted December 3, 2009 Thanks Link to comment Share on other sites More sharing options...
meisandy Posted December 4, 2009 Author Share Posted December 4, 2009 HI, Actually now testing it with all three of my input boxes using that snippet of a script. I cannot type anything with out going back to ""? And instead of it going back to "" if the focous is lost I need it to only do that if nothing is in the input box! Please!? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2009 Moderators Share Posted December 4, 2009 DjATUit, I am not a mind reader. Please post the script so I can see it! 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 4, 2009 Author Share Posted December 4, 2009 Sorry: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=T:\icons\icandy Icons\iCandy Junior\The Icons\Home 2.ico #AutoIt3Wrapper_Res_Comment=This program speeds up the process of typing "Learning Objective" and "To be able to". By using Windows key and Alt followed by l or t #AutoIt3Wrapper_Res_Description=Speeding up typing at school! #AutoIt3Wrapper_Res_Fileversion=1.0 Beta #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> ; <<<<<<<<<<<<<<<<<<< Not as many now!!! #include <EditConstants.au3> #include <WinAPI.au3> Global $HK1_String = "", $HK2_String = "", $HK3_String = "", $HK3_Check, $HK1_Check, $HK2_Check, $rd1hkout, $rd2hkout, $rd3hkout, $GUI_FOCOUS, $Input_flag ; <<<<< And not so many here either! Opt("TrayMenuMode", 3) ; <<<<<<<< Added 2 = Do not tick when selected Global $SetKeyBoardShortcutsTray = TrayCreateItem("Set Keyboard Shortcuts") Global $AboutTray = TrayCreateItem ("About") Global $EscScript = TrayCreateItem("Exit") HotKeySet("{ESCAPE}", "stoptxt") HotKeySet("#!l", "TypeLO") HotKeySet("#!t", "TYPEtbat") ;GUICtrlSetOnEvent($ButtonOKCP, "ButtonOKCP") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not in OnEvent mode ;$sCurr_Combo = "" ; no longer needed ;$turninhots1_1 = "" ; <<<<<<<<<<<<<< no longer needed ;$turninhots1_2 = "" ;$turninhots1_3 = "" ;$turninhots2_1 = "" ;$turninhots2_2 = "" ; Create GUI Global $Form1 = GUICreate("About SB 1.1", 212, 158, 192, 124) $Label1 = GUICtrlCreateLabel("About SchoolBoard 1.1", 8, 8, 198, 17) $Label2 = GUICtrlCreateLabel("This program was created to set hotkeys", 8, 32, 195, 17) $Label3 = GUICtrlCreateLabel("to speed up typing, as a demo it brings up ", 8, 48, 203, 17) $Label4 = GUICtrlCreateLabel("a message box showing you hot key and", 8, 64, 196, 17) $Label5 = GUICtrlCreateLabel("your message. Bugs may occour! I am ", 8, 80, 186, 17) $Label6 = GUICtrlCreateLabel("Fully Aware and working on a Fix", 8, 96, 159, 17) $Label7 = GUICtrlCreateLabel("Created by Andrew Green", 8, 120, 126, 17) $Label8 = GUICtrlCreateLabel("@ drewscyberworld.net", 96, 136, 115, 17) GUISetState(@SW_HIDE) Global $Form2 = GUICreate("Control Panel for SchoolBoard", 482, 330, 302, 218) GUISetIcon("D:\005.ico") Global $PageControl1 = GUICtrlCreateTab(8, 8, 436, 256) ;GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) ; <<<<<<<<<<<<<<<<<< Not needed, you do not have a resizeable GUI Global $TabSheet1 = GUICtrlCreateTabItem("Keyboard Shortcuts") ; These are reordered to make it a bit easier to work out what is going on!! GUICtrlCreateLabel("First Key", 24, 56, 47, 18) ; <<<<<< You only need to use variables for the ControlID if you are going to use it later GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Second Key", 104, 56, 63, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Letter", 191, 56, 32, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $firsthklabel = GUICtrlCreateLabel("Phrase/ Sentence", 260, 54, 84, 18) GUICtrlSetState(-1,$GUI_FOCOUS) GUICtrlSetFont(-1, 8, 400, 0, "Arial") Global $Combofirstset1 = GUICtrlCreateCombo("Win", 24, 80, 49, 25) ; <<<< You need this one for example GUICtrlSetData(-1, "Alt|Ctrl") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 80, 80, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combofirstset2 = GUICtrlCreateCombo("Alt", 105, 79, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 170, 80, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combofirstsetletter = GUICtrlCreateCombo("a", 193, 79, 49, 25) GUICtrlSetData(-1, "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("=", 249, 79, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Inputfirsthk = GUICtrlCreateInput("Type your sentence here", 264, 80, 169, 22) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Input1_focous_handle = GUICtrlGetHandle(-1) GUICtrlCreateLabel("First Key", 24, 117, 47, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Second Key", 104, 114, 63, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Letter", 191, 110, 32, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $secondhklabel = GUICtrlCreateLabel("Phrase/ Sentence", 260, 115, 84, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") Global $Comboscndset1 = GUICtrlCreateCombo("Win", 25, 138, 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 81, 140, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Comboscndset2 = GUICtrlCreateCombo("Alt", 105, 137, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 170, 135, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Comboscndsetletter = GUICtrlCreateCombo("a", 193, 133, 49, 25) GUICtrlSetData(-1, "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("=", 249, 136, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Inputscndhk = GUICtrlCreateInput("Type your sentence here", 263, 135, 169, 22) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Input2_focous_handle = GUICtrlGetHandle(-1) GUICtrlCreateLabel("First Key", 24, 176, 47, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Second Key", 104, 173, 63, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Letter", 191, 173, 32, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Phrase/ Sentence", 260, 171, 84, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") Global $Combothrdset1 = GUICtrlCreateCombo("Win", 25, 197, 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 81, 194, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combothrdset2 = GUICtrlCreateCombo("Alt", 103, 195, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 169, 194, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combothrdsetletter = GUICtrlCreateCombo("a", 193, 197, 49, 25) GUICtrlSetData(-1, "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("=", 249, 197, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Inputthrdhk = GUICtrlCreateInput("Type your sentence here", 266, 195, 169, 22 ) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Input3_focous_handle = GUICtrlGetHandle(-1) GUICtrlCreateTabItem("") Global $ButtonOKCP = GUICtrlCreateButton("&OK", 166, 272, 75, 25) ; Not needed here >> , $WS_GROUP) Global $Button2 = GUICtrlCreateButton("&Cancel", 246, 272, 75, 25) ;, $WS_GROUP) Global $Button3 = GUICtrlCreateButton("&Help", 328, 272, 75, 25) ;, $WS_GROUP) GUISetState(@SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<< Hide GUI until needed $Input_flag =False While 1 ; Look for tray events Switch TrayGetMsg() Case $EscScript ; Exit script completely Exit Case $SetKeyBoardShortcutsTray ; Show the GUI so we can set HotKeys GUISetState(@SW_SHOW, $Form2) Case $AboutTray GUISetState(@SW_SHOW, $Form1) EndSwitch ; Look for GUI events Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $Form2 GUISetState(@SW_HIDE, $Form2) Case $GUI_EVENT_CLOSE, $Form1 GUISetState(@SW_HIDE, $Form1) Case $GUI_EVENT_CLOSE, $Button2 ; Hide GUI again without changing HotKeys GUISetState(@SW_HIDE, $Form2) Case $ButtonOKCP ; Change HotKeys and then hide GUI again Change_HotKeys() GUISetState(@SW_HIDE, $Form2) Case $Button3 ; Show some Help - I hope! EndSwitch $1hk_focoused = _WinAPI_GetFocus () If $1hk_focoused = $Input1_focous_handle Then If $Input_flag = False Then $Input_flag = True GUICtrlSetData($Inputfirsthk, "") EndIf Else $Input_flag = False GUICtrlSetData($Inputfirsthk, "Type your sentance here!") EndIf $2hk_focoused = _WinAPI_GetFocus () If $2hk_focoused = $Input2_focous_handle Then If $Input_flag = False Then $Input_flag = True GUICtrlSetData($Inputscndhk, "") EndIf Else $Input_flag = False GUICtrlSetData($Inputscndhk, "Type your sentance here!") EndIf $3hk_focoused = _WinAPI_GetFocus () If $3hk_focoused = $Input3_focous_handle Then If $Input_flag = False Then $Input_flag = True GUICtrlSetData ($Inputthrdhk, "") EndIf Else $Input_flag = False GUICtrlSetData($Inputthrdhk, "Type your sentance here!") EndIf ;Sleep(100) ; <<<<<<<<<<<<<<<<<<<<<<< Only needed if you are in OnEvent mode WEnd ;Func ButtonOKCP() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not needed, we are not in OnEvent mode ; Exit ;EndFunc ;==>ButtonOKCP Func Change_HotKeys() ; Reset first HotKey ; Unset current key HotKeySet($HK1_String) ; Now set HotKey string to blank $HK1_String = "" ; Get character for first combo selection and add to string $HK1_String &= Get_Char($Combofirstset1) ; Get character for second combo selection and add to string $HK1_String &= Get_Char($Combofirstset2) ; Add key character to string $HK1_String &= GUICtrlRead($Combofirstsetletter) ; Set required phrase $rd1hkout = GUICtrlRead($Inputfirsthk) ; Set check string $HK1_Check = GUICtrlRead($Combofirstset1) & " - " & GUICtrlRead($Combofirstset2) & " - " & GUICtrlRead($Combofirstsetletter) ; Set the new key HotKeySet($HK1_String, "UserHotKey1") ; Reset second HotKey ; Unset current key HotKeySet($HK2_String) ; Now set HotKey string to blank $HK2_String = "" ; Get character for first combo selection and add to string $HK2_String &= Get_Char($Comboscndset1) ; Get character for second combo selection and add to string $HK2_String &= Get_Char($Comboscndset2) ; Add key character to string $HK2_String &= GUICtrlRead($Comboscndsetletter) ; Set required phrase $rd2hkout = GUICtrlRead($Inputscndhk) ; Set check string $HK2_Check = GUICtrlRead($Comboscndset1) & " - " & GUICtrlRead($Comboscndset2) & " - " & GUICtrlRead($Comboscndsetletter) ; Set the new key HotKeySet($HK2_String, "UserHotKey3") HotKeySet($HK3_String) $HK3_String = "" $HK3_String &= Get_Char($Combothrdset1) $HK3_String &= Get_Char($Combothrdset2) $HK3_String &= GUICtrlRead($Combothrdsetletter) $rd3hkout = GUICtrlRead($Inputthrdhk) $HK3_Check = GUICtrlRead($Combothrdset1) & " - " & GUICtrlRead($Combothrdset2) & " - " & GUICtrlRead($Combothrdsetletter) HotKeySet($HK3_String, "UserHotKey3") EndFunc Func Get_Char($Combo) Local $sRet ; Set value according to combo value Switch GUICtrlRead($Combo) Case "Alt" $sRet = "!" Case "Win" $sRet = "#" Case "Ctrl" $sRet = "^" EndSwitch ; Return value Return $sRet EndFunc Func stoptxt() Exit 0 EndFunc ;==>stoptxt Func UserHotkey3() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK3_Check & @CRLF & "Your Message Is: " & $rd3hkout) EndFunc Func UserHotkey2() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK2_Check & @CRLF & "Your Message Is: " & $rd2hkout) EndFunc ;==>UserHotkey2 Func UserHotKey1() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK1_Check & @CRLF & "Your Message Is: " & $rd1hkout) ; Send($rd1hkout) ; <<<<<<<<<<<<<<<< what you will need! EndFunc ;==>UserHotKey1 Func TypeLO() Send("Learning Objective") EndFunc ;==>TypeLO Func TYPEtbat() Send("To be able to") EndFunc ;==>TYPEtbat Line 173 - 203 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2009 Moderators Share Posted December 4, 2009 DjATUit, Here we go - I hope: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=T:\icons\icandy Icons\iCandy Junior\The Icons\Home 2.ico #AutoIt3Wrapper_Res_Comment=This program speeds up the process of typing "Learning Objective" and "To be able to". By using Windows key and Alt followed by l or t #AutoIt3Wrapper_Res_Description=Speeding up typing at school! #AutoIt3Wrapper_Res_Fileversion=1.0 Beta #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> ; <<<<<<<<<<<<<<<<<<< Not as many now!!! #include <EditConstants.au3> #include <WinAPI.au3> Global $HK1_String = "", $HK2_String = "", $HK3_String = "", $HK3_Check, $HK1_Check, $HK2_Check, $rd1hkout, $rd2hkout, $rd3hkout, $GUI_FOCOUS, $Input_flag ; <<<<< And not so many here either! Opt("TrayMenuMode", 3) ; <<<<<<<< Added 2 = Do not tick when selected Global $SetKeyBoardShortcutsTray = TrayCreateItem("Set Keyboard Shortcuts") Global $AboutTray = TrayCreateItem("About") Global $EscScript = TrayCreateItem("Exit") HotKeySet("{ESCAPE}", "stoptxt") HotKeySet("#!l", "TypeLO") HotKeySet("#!t", "TYPEtbat") ;GUICtrlSetOnEvent($ButtonOKCP, "ButtonOKCP") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not in OnEvent mode ;$sCurr_Combo = "" ; no longer needed ;$turninhots1_1 = "" ; <<<<<<<<<<<<<< no longer needed ;$turninhots1_2 = "" ;$turninhots1_3 = "" ;$turninhots2_1 = "" ;$turninhots2_2 = "" ; Create GUI Global $Form1 = GUICreate("About SB 1.1", 212, 148, 192, 124) $sMsg = "About SchoolBoard 1.1" & @CRLF & @CRLF & "This program was created to set hotkeys" & @CRLF & "to speed up typing, as a demo it brings up" _ & @CRLF & "a message box showing you hot key and" & @CRLF & "your message. Bugs may occour! I am " & @CRLF & "Fully Aware and working on a Fix" _ & @CRLF & @CRLF & "Created by Andrew Green" & @CRLF & "@ drewscyberworld.net" $Label1 = GUICtrlCreateLabel($sMsg, 8, 8, 203, 136) #cs $Label1 = GUICtrlCreateLabel("About SchoolBoard 1.1", 8, 8, 198, 17) $Label2 = GUICtrlCreateLabel("This program was created to set hotkeys", 8, 32, 195, 17) $Label3 = GUICtrlCreateLabel("to speed up typing, as a demo it brings up ", 8, 48, 203, 17) $Label4 = GUICtrlCreateLabel("a message box showing you hot key and", 8, 64, 196, 17) $Label5 = GUICtrlCreateLabel("your message. Bugs may occour! I am ", 8, 80, 186, 17) $Label6 = GUICtrlCreateLabel("Fully Aware and working on a Fix", 8, 96, 159, 17) $Label7 = GUICtrlCreateLabel("Created by Andrew Green", 8, 120, 126, 17) $Label8 = GUICtrlCreateLabel("@ drewscyberworld.net", 96, 136, 115, 17) #ce GUISetState(@SW_HIDE) Global $Form2 = GUICreate("Control Panel for SchoolBoard", 482, 330, 302, 218) GUISetIcon("D:\005.ico") Global $PageControl1 = GUICtrlCreateTab(8, 8, 436, 256) ;GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT) ; <<<<<<<<<<<<<<<<<< Not needed, you do not have a resizeable GUI Global $TabSheet1 = GUICtrlCreateTabItem("Keyboard Shortcuts") ; These are reordered to make it a bit easier to work out what is going on!! GUICtrlCreateLabel("First Key", 24, 56, 47, 18) ; <<<<<< You only need to use variables for the ControlID if you are going to use it later GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Second Key", 104, 56, 63, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Letter", 191, 56, 32, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $firsthklabel = GUICtrlCreateLabel("Phrase/ Sentence", 260, 54, 84, 18) GUICtrlSetState(-1, $GUI_FOCOUS) GUICtrlSetFont(-1, 8, 400, 0, "Arial") Global $Combofirstset1 = GUICtrlCreateCombo("Win", 24, 80, 49, 25) ; <<<< You need this one for example GUICtrlSetData(-1, "Alt|Ctrl") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 80, 80, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combofirstset2 = GUICtrlCreateCombo("Alt", 105, 79, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 170, 80, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combofirstsetletter = GUICtrlCreateCombo("a", 193, 79, 49, 25) GUICtrlSetData(-1, "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("=", 249, 79, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Inputfirsthk = GUICtrlCreateInput("Type your sentence here", 264, 80, 169, 22) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Input1_focous_handle = GUICtrlGetHandle(-1) GUICtrlCreateLabel("First Key", 24, 117, 47, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Second Key", 104, 114, 63, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Letter", 191, 110, 32, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $secondhklabel = GUICtrlCreateLabel("Phrase/ Sentence", 260, 115, 84, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") Global $Comboscndset1 = GUICtrlCreateCombo("Win", 25, 138, 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 81, 140, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Comboscndset2 = GUICtrlCreateCombo("Alt", 105, 137, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 170, 135, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Comboscndsetletter = GUICtrlCreateCombo("a", 193, 133, 49, 25) GUICtrlSetData(-1, "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("=", 249, 136, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Inputscndhk = GUICtrlCreateInput("Type your sentence here", 263, 135, 169, 22) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Input2_focous_handle = GUICtrlGetHandle(-1) GUICtrlCreateLabel("First Key", 24, 176, 47, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Second Key", 104, 173, 63, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Letter", 191, 173, 32, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Phrase/ Sentence", 260, 171, 84, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") Global $Combothrdset1 = GUICtrlCreateCombo("Win", 25, 197, 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 81, 194, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combothrdset2 = GUICtrlCreateCombo("Alt", 103, 195, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 169, 194, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Combothrdsetletter = GUICtrlCreateCombo("a", 193, 197, 49, 25) GUICtrlSetData(-1, "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("=", 249, 197, 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") Global $Inputthrdhk = GUICtrlCreateInput("Type your sentence here", 266, 195, 169, 22) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Input3_focous_handle = GUICtrlGetHandle(-1) GUICtrlCreateTabItem("") Global $ButtonOKCP = GUICtrlCreateButton("&OK", 166, 272, 75, 25) ; Not needed here >> , $WS_GROUP) Global $Button2 = GUICtrlCreateButton("&Cancel", 246, 272, 75, 25) ;, $WS_GROUP) Global $Button3 = GUICtrlCreateButton("&Help", 328, 272, 75, 25) ;, $WS_GROUP) GUISetState(@SW_HIDE) ; <<<<<<<<<<<<<<<<<<<<<<< Hide GUI until needed $Input_flag_first = False ; <<<<< Set 2 flags - one for each Input $Input_flag_scnd = False $Input_flag_thrd = False While 1 ; Look for tray events Switch TrayGetMsg() Case $EscScript ; Exit script completely Exit Case $SetKeyBoardShortcutsTray ; Show the GUI so we can set HotKeys GUISetState(@SW_SHOW, $Form2) Case $AboutTray GUISetState(@SW_SHOW, $Form1) ; <<<<<<<<<<<<<<<<<<< Show the About GUI and wait for it to be closed While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then GUISetState(@SW_HIDE, $Form1) ExitLoop EndIf WEnd EndSwitch ; Look for GUI events Switch GUIGetMsg() #cs ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not sure why you added these? Case $GUI_EVENT_CLOSE, $Form2 GUISetState(@SW_HIDE, $Form2) Case $GUI_EVENT_CLOSE, $Form1 GUISetState(@SW_HIDE, $Form1) #ce Case $GUI_EVENT_CLOSE, $Button2 ; Hide GUI again without changing HotKeys GUISetState(@SW_HIDE, $Form2) Case $ButtonOKCP ; Change HotKeys and then hide GUI again Change_HotKeys() GUISetState(@SW_HIDE, $Form2) Case $Button3 ; Show some Help - I hope! EndSwitch $hFocused = _WinAPI_GetFocus() ; See what has focus Switch $hFocused Case $Input1_focous_handle ; It is the first input If $Input_flag_first = False Then ; If the flag for the first input is not set GUICtrlSetData($Inputfirsthk, "") ; Set the input to blank $Input_flag_first = True ; So set the flag for the first input EndIf $Input_flag_scnd = False ; Reet the flags for the other 2 inputs and reset the text if they are blank If GUICtrlRead($Inputscndhk) = "" Then GUICtrlSetData($Inputscndhk, "Type your sentence here!") $Input_flag_thrd = False If GUICtrlRead($Inputthrdhk) = "" Then GUICtrlSetData($Inputthrdhk, "Type your sentence here!") Case $Input2_focous_handle If $Input_flag_scnd = False Then GUICtrlSetData($Inputscndhk, "") $Input_flag_scnd = True EndIf $Input_flag_first = False If GUICtrlRead($Inputfirsthk) = "" Then GUICtrlSetData($Inputfirsthk, "Type your sentence here!") $Input_flag_thrd = False If GUICtrlRead($Inputthrdhk) = "" Then GUICtrlSetData($Inputthrdhk, "Type your sentence here!") Case $Input3_focous_handle If $Input_flag_thrd = False Then GUICtrlSetData($Inputthrdhk, "") $Input_flag_thrd = True EndIf $Input_flag_first = False If GUICtrlRead($Inputfirsthk) = "" Then GUICtrlSetData($Inputfirsthk, "Type your sentence here!") $Input_flag_scnd = False If GUICtrlRead($Inputscndhk) = "" Then GUICtrlSetData($Inputscndhk, "Type your sentence here!") EndSwitch ;Sleep(100) ; <<<<<<<<<<<<<<<<<<<<<<< Only needed if you are in OnEvent mode WEnd ;Func ButtonOKCP() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Not needed, we are not in OnEvent mode ; Exit ;EndFunc ;==>ButtonOKCP Func Change_HotKeys() ; Reset first HotKey ; Unset current key HotKeySet($HK1_String) ; Now set HotKey string to blank $HK1_String = "" ; Get character for first combo selection and add to string $HK1_String &= Get_Char($Combofirstset1) ; Get character for second combo selection and add to string $HK1_String &= Get_Char($Combofirstset2) ; Add key character to string $HK1_String &= GUICtrlRead($Combofirstsetletter) ; Set required phrase $rd1hkout = GUICtrlRead($Inputfirsthk) ; Set check string $HK1_Check = GUICtrlRead($Combofirstset1) & " - " & GUICtrlRead($Combofirstset2) & " - " & GUICtrlRead($Combofirstsetletter) ; Set the new key HotKeySet($HK1_String, "UserHotKey1") ; Reset second HotKey ; Unset current key HotKeySet($HK2_String) ; Now set HotKey string to blank $HK2_String = "" ; Get character for first combo selection and add to string $HK2_String &= Get_Char($Comboscndset1) ; Get character for second combo selection and add to string $HK2_String &= Get_Char($Comboscndset2) ; Add key character to string $HK2_String &= GUICtrlRead($Comboscndsetletter) ; Set required phrase $rd2hkout = GUICtrlRead($Inputscndhk) ; Set check string $HK2_Check = GUICtrlRead($Comboscndset1) & " - " & GUICtrlRead($Comboscndset2) & " - " & GUICtrlRead($Comboscndsetletter) ; Set the new key HotKeySet($HK2_String, "UserHotKey3") HotKeySet($HK3_String) $HK3_String = "" $HK3_String &= Get_Char($Combothrdset1) $HK3_String &= Get_Char($Combothrdset2) $HK3_String &= GUICtrlRead($Combothrdsetletter) $rd3hkout = GUICtrlRead($Inputthrdhk) $HK3_Check = GUICtrlRead($Combothrdset1) & " - " & GUICtrlRead($Combothrdset2) & " - " & GUICtrlRead($Combothrdsetletter) HotKeySet($HK3_String, "UserHotKey3") EndFunc ;==>Change_HotKeys Func Get_Char($Combo) Local $sRet ; Set value according to combo value Switch GUICtrlRead($Combo) Case "Alt" $sRet = "!" Case "Win" $sRet = "#" Case "Ctrl" $sRet = "^" EndSwitch ; Return value Return $sRet EndFunc ;==>Get_Char Func stoptxt() Exit 0 EndFunc ;==>stoptxt Func UserHotkey3() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK3_Check & @CRLF & "Your Message Is: " & $rd3hkout) EndFunc ;==>UserHotkey3 Func UserHotkey2() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK2_Check & @CRLF & "Your Message Is: " & $rd2hkout) EndFunc ;==>UserHotkey2 Func UserHotKey1() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK1_Check & @CRLF & "Your Message Is: " & $rd1hkout) ; Send($rd1hkout) ; <<<<<<<<<<<<<<<< what you will need! EndFunc ;==>UserHotKey1 Func TypeLO() Send("Learning Objective") EndFunc ;==>TypeLO Func TYPEtbat() Send("To be able to") EndFunc ;==>TYPEtbat I have commented where I have changed things - as usual look for the <<<<<<<<<<<<<<<<<<<<< lines. I have also shown you how to make a single label for a multi-line message. You need to bear in mind that the short code examples that you get in reply to your questions are self contained and are not "plug-and-play" modules to insert in your script. They normally indicate a method of solving a problem, which you then need to adapt to your specific script. For example, the input box code I gave you was good for 1 input box - you can see above how it bears only a passing resemblance to the way I have coded for 3! You need to make sure you understand WHY a certain code works so you can then alter it to fit what you need to do. Besides it is more fun playing around with code - where is the satisfaction in just plugging in what someone else has written. Anyway, please ask if anything is unclear, but not for the next hour - I will be watching the draw for the World Cup! 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 4, 2009 Author Share Posted December 4, 2009 Yeah, totally, it works fine! You've been so helpful and I've learnt alot from you! Its all part of learning(getting things wrong and messing around)! Thanks Melba23 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2009 Moderators Share Posted December 4, 2009 (edited) DjATUit,Here is a version of your script that I have tidied a lot to show you how it can become easier to read - and save wear on the typing fingers! expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=T:\icons\icandy Icons\iCandy Junior\The Icons\Home 2.ico #AutoIt3Wrapper_Res_Comment=This program speeds up the process of typing "Learning Objective" and "To be able to". By using Windows key and Alt followed by l or t #AutoIt3Wrapper_Res_Description=Speeding up typing at school! #AutoIt3Wrapper_Res_Fileversion=1.0 Beta #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WinAPI.au3> Global $sHK1_String = "", $sHK2_String = "", $sHK3_String = "" Global $sHK1_Check, $sHK2_Check, $sHK3_Check Global $sHK_Msg_1, $sHK_Msg_2, $sHK_Msg_3 Global $fInput_Flag_1 = False, $fInput_Flag_scnd = False, $fInput_Flag_thrd = False ; Create menu Opt("TrayMenuMode", 3) Global $hSetHK_Tray = TrayCreateItem("Set Keyboard Shortcuts") Global $hAbout_Tray = TrayCreateItem("About") Global $hExit_Tray = TrayCreateItem("Exit") ; Set HotKeys HotKeySet("{ESCAPE}", "On_Exit") HotKeySet("#!l", "TypeLO") HotKeySet("#!t", "TYPEtbat") ; Create GUIs ; Create About GUI Global $hAbout_Win = GUICreate("About SB 1.1", 212, 148, 192, 124) $sAbout_Msg = "About SchoolBoard 1.1" & @CRLF & @CRLF & "This program was created to set hotkeys" & @CRLF & "to speed up typing, as a demo it brings up" _ & @CRLF & "a message box showing you hot key and" & @CRLF & "your message. Bugs may occour! I am " & @CRLF & "Fully Aware and working on a Fix" _ & @CRLF & @CRLF & "Created by Andrew Green" & @CRLF & "@ drewscyberworld.net" $hAbout_Label = GUICtrlCreateLabel($sAbout_Msg, 8, 8, 203, 136) GUISetState(@SW_HIDE) ; Create HotKey GUI Global $hHotKey_Win = GUICreate("Control Panel for SchoolBoard", 482, 330, 302, 218) GUISetIcon("D:\005.ico") GUICtrlCreateTab(8, 8, 436, 256) GUICtrlCreateTabItem("Keyboard Shortcuts") $hControl_Start = GUICtrlCreateDummy() ; This is here so we know the start of the ControlIDs of the controls in the loop For $i = 1 To 3 GUICtrlCreateLabel("First Key", 24, ($i * 60) - 4, 47, 18) GUICtrlCreateLabel("Second Key", 104, ($i * 60) - 4, 63, 18) GUICtrlCreateLabel("Letter", 191, ($i * 60) - 4, 32, 18) GUICtrlCreateLabel("Phrase/ Sentence", 260, ($i * 60) - 4, 84, 18) Next $hControl_End = GUICtrlCreateDummy() ; This is here so we know the end of the ControlIDs of the controls in the loop For $i = $hControl_Start To $hControl_End ; And we use these values to loop through all the controls like this GUICtrlSetFont($i, 8, 400, 0, "Arial") Next $hControl_Start = GUICtrlCreateDummy() For $i = 1 To 3 GUICtrlCreateLabel("+", 80, ($i * 60) + 20, 13, 22) GUICtrlCreateLabel("+", 170, ($i * 60) + 20, 13, 22) GUICtrlCreateLabel("=", 249, ($i * 60) + 20, 13, 22) Next $hControl_End = GUICtrlCreateDummy() For $i = $hControl_Start To $hControl_End GUICtrlSetFont($i, 12, 400, 0, "Arial") Next ; Create things that are used often just once and then use the variable ; Saves the typing finger! $sKey_List = "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z" $sDefault_Text = "Type your sentence here!" ; We could make these into a loop - but it can give problems with naming the variables $hControl_Start = GUICtrlCreateDummy() Global $hCombo_HK1_Mod_1 = GUICtrlCreateCombo("Win", 24, 80, 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") Global $hCombo_HK1_Mod_2 = GUICtrlCreateCombo("Alt", 105, 80, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") Global $hCombo_HK1_Key = GUICtrlCreateCombo("a", 193, 80, 49, 25) GUICtrlSetData(-1, $sKey_List) Global $hCombo_HK1_Text = GUICtrlCreateInput($sDefault_Text, 264, 80, 169, 22) $hInputHK_Handle_1 = GUICtrlGetHandle(-1) Global $hCombo_HK2_Mod_1 = GUICtrlCreateCombo("Win", 25, 140, 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") Global $hCombo_HK2_Mod_2 = GUICtrlCreateCombo("Alt", 105, 140, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") Global $hCombo_HK2_Key = GUICtrlCreateCombo("a", 193, 140, 49, 25) GUICtrlSetData(-1, $sKey_List) Global $hCombo_HK2_Text = GUICtrlCreateInput($sDefault_Text, 264, 140, 169, 22) $hInputHK_Handle_2 = GUICtrlGetHandle(-1) Global $hCombo_HK3_Mod_1 = GUICtrlCreateCombo("Win", 25, 200, 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") Global $hCombo_HK3_Mod_2 = GUICtrlCreateCombo("Alt", 105, 200, 49, 25) GUICtrlSetData(-1, "Ctrl|Win") Global $hCombo_HK3_Key = GUICtrlCreateCombo("a", 193, 200, 49, 25) GUICtrlSetData(-1, $sKey_List) Global $hCombo_HK3_Text = GUICtrlCreateInput($sDefault_Text, 264, 200, 169, 22) $hInputHK_Handle_3 = GUICtrlGetHandle(-1) $hControl_End = GUICtrlCreateDummy() For $i = $hControl_Start To $hControl_End GUICtrlSetFont($i, 8, 400, 0, "Arial") Next GUICtrlCreateTabItem("") ; Create buttons - and give them meaningful names Global $hButton_Change = GUICtrlCreateButton("&OK", 166, 272, 75, 25) Global $hButton_Cancel = GUICtrlCreateButton("&Cancel", 246, 272, 75, 25) Global $hButton_Help = GUICtrlCreateButton("&Help", 328, 272, 75, 25) GUISetState(@SW_HIDE) While 1 ; Look for tray events Switch TrayGetMsg() Case $hExit_Tray ; Exit script completely Exit Case $hSetHK_Tray ; Show the GUI so we can set HotKeys GUISetState(@SW_SHOW, $hHotKey_Win) Case $hAbout_Tray ; Show the About GUI and wait for it to be closed GUISetState(@SW_SHOW, $hAbout_Win) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then GUISetState(@SW_HIDE, $hAbout_Win) ExitLoop EndIf WEnd EndSwitch ; Look for GUI events Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $hButton_Cancel ; Hide GUI again without changing HotKeys GUISetState(@SW_HIDE, $hHotKey_Win) Case $hButton_Change ; Change HotKeys and then hide GUI again Change_HotKeys() GUISetState(@SW_HIDE, $hHotKey_Win) Case $hButton_Help ; Show some Help - I hope! EndSwitch $hFocused = _WinAPI_GetFocus() ; See what has focus Switch $hFocused Case $hInputHK_Handle_1 ; It is the first input If $fInput_Flag_1 = False Then ; If the flag for the first input is not set GUICtrlSetData($hCombo_HK1_Text, "") ; Set the input to blank $fInput_Flag_1 = True ; So set the flag for the first input EndIf $fInput_Flag_scnd = False ; Reet the flags for the other 2 inputs and reset the text if they are blank If GUICtrlRead($hCombo_HK2_Text) = "" Then GUICtrlSetData($hCombo_HK2_Text, $sDefault_Text) $fInput_Flag_thrd = False If GUICtrlRead($hCombo_HK3_Text) = "" Then GUICtrlSetData($hCombo_HK3_Text, $sDefault_Text) Case $hInputHK_Handle_2 If $fInput_Flag_scnd = False Then GUICtrlSetData($hCombo_HK2_Text, "") $fInput_Flag_scnd = True EndIf $fInput_Flag_1 = False If GUICtrlRead($hCombo_HK1_Text) = "" Then GUICtrlSetData($hCombo_HK1_Text, $sDefault_Text) $fInput_Flag_thrd = False If GUICtrlRead($hCombo_HK3_Text) = "" Then GUICtrlSetData($hCombo_HK3_Text, $sDefault_Text) Case $hInputHK_Handle_3 If $fInput_Flag_thrd = False Then GUICtrlSetData($hCombo_HK3_Text, "") $fInput_Flag_thrd = True EndIf $fInput_Flag_1 = False If GUICtrlRead($hCombo_HK1_Text) = "" Then GUICtrlSetData($hCombo_HK1_Text, $sDefault_Text) $fInput_Flag_scnd = False If GUICtrlRead($hCombo_HK2_Text) = "" Then GUICtrlSetData($hCombo_HK2_Text, $sDefault_Text) EndSwitch WEnd Func Change_HotKeys() ; Reset first HotKey ; Unset current key HotKeySet($sHK1_String) ; Now set HotKey string to blank $sHK1_String = "" ; Get character for first combo selection and add to string $sHK1_String &= Get_Char($hCombo_HK1_Mod_1) ; Get character for second combo selection and add to string $sHK1_String &= Get_Char($hCombo_HK1_Mod_2) ; Add key character to string $sHK1_String &= GUICtrlRead($hCombo_HK1_Key) ; Set required phrase $sHK_Msg_1 = GUICtrlRead($hCombo_HK1_Text) ; Set check string $sHK1_Check = GUICtrlRead($hCombo_HK1_Mod_1) & " - " & GUICtrlRead($hCombo_HK1_Mod_2) & " - " & GUICtrlRead($hCombo_HK1_Key) ; Set the new key HotKeySet($sHK1_String, "UserHotKey1") ; Reset second HotKey ; Unset current key HotKeySet($sHK2_String) ; Now set HotKey string to blank $sHK2_String = "" ; Get character for first combo selection and add to string $sHK2_String &= Get_Char($hCombo_HK2_Mod_1) ; Get character for second combo selection and add to string $sHK2_String &= Get_Char($hCombo_HK2_Mod_2) ; Add key character to string $sHK2_String &= GUICtrlRead($hCombo_HK2_Key) ; Set required phrase $sHK_Msg_2 = GUICtrlRead($hCombo_HK2_Text) ; Set check string $sHK2_Check = GUICtrlRead($hCombo_HK2_Mod_1) & " - " & GUICtrlRead($hCombo_HK2_Mod_2) & " - " & GUICtrlRead($hCombo_HK2_Key) ; Set the new key HotKeySet($sHK2_String, "UserHotKey3") HotKeySet($sHK3_String) $sHK3_String = "" $sHK3_String &= Get_Char($hCombo_HK3_Mod_1) $sHK3_String &= Get_Char($hCombo_HK3_Mod_2) $sHK3_String &= GUICtrlRead($hCombo_HK3_Key) $sHK_Msg_3 = GUICtrlRead($hCombo_HK3_Text) $sHK3_Check = GUICtrlRead($hCombo_HK3_Mod_1) & " - " & GUICtrlRead($hCombo_HK3_Mod_2) & " - " & GUICtrlRead($hCombo_HK3_Key) HotKeySet($sHK3_String, "UserHotKey3") EndFunc ;==>Change_HotKeys Func Get_Char($hCombo) Local $sRet ; Set value according to combo value Switch GUICtrlRead($hCombo) Case "Alt" $sRet = "!" Case "Win" $sRet = "#" Case "Ctrl" $sRet = "^" EndSwitch ; Return value Return $sRet EndFunc ;==>Get_Char Func On_Exit() Exit 0 EndFunc ;==>On_Exit Func UserHotKey1() MsgBox(0, "Success", "Your new hot key 1 is: " & $sHK1_Check & @CRLF & "Your Message Is: " & $sHK_Msg_1) ; Send($sHK_Msg_1) ; <<<<<<<<<<<<<<<< what you will need! EndFunc ;==>UserHotKey1 Func UserHotkey2() MsgBox(0, "Success", "Your new hot key 1 is: " & $sHK2_Check & @CRLF & "Your Message Is: " & $sHK_Msg_2) EndFunc ;==>UserHotkey2 Func UserHotkey3() MsgBox(0, "Success", "Your new hot key 1 is: " & $sHK3_Check & @CRLF & "Your Message Is: " & $sHK_Msg_3) EndFunc ;==>UserHotkey3 Func TypeLO() Send("Learning Objective") EndFunc ;==>TypeLO Func TYPEtbat() Send("To be able to") EndFunc ;==>TYPEtbatNow, there was nothing actually wrong with your script as it stood (it worked!) but I hope you can see how using meaningful variable names and loops can really clarify code - when you came back to something after a few months (or even weeks!) having clear, commented code is something for which you will be eternally grateful. Forget this "Real programmers don't comment - if it was hard to write, it should be hard to understand" BS - remember that you have to maintain/develop/modify the code, so make it as limpid as possible! As always, please ask if you have any questions.M23 Edited December 4, 2009 by Melba23 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 4, 2009 Author Share Posted December 4, 2009 it has too errors which i personally dont get: C:\Users\DJ Drew\Desktop\sbtst.au3(81,20) : ERROR: syntax error GUICtrlSetData(-1, ) ~~~~~~~~~~~~~~~~~~~^ C:\Users\DJ Drew\Desktop\sbtst.au3(181,1) : ERROR: missing Next. Func ^ C:\Users\DJ Drew\Desktop\sbtst.au3(59,12) : REF: missing Next. For $i = 1 To ~~~~~~~~~~~^ C:\Users\DJ Drew\Desktop\sbtst.au3 - 2 error(s), 0 warning(s) I have copied the script exactly Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 4, 2009 Moderators Share Posted December 4, 2009 DjATUit,My apologies - I have no idea what happened there. I have reset the script in my previous post - there was a missing Next - and its absence confuses me greatly. Anyway, the point was the reworking of the code to make it clearer - not the code itself. I will try to look at the code again over the weekend to see if I can get it even tighter - how up to speed are you on arrays? 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 5, 2009 Author Share Posted December 5, 2009 I don't really work or know arrays. What ive got so far is probably as far as it goes with me for now! Link to comment Share on other sites More sharing options...
meisandy Posted December 13, 2009 Author Share Posted December 13, 2009 I can use and know arrays now! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 13, 2009 Moderators Share Posted December 13, 2009 (edited) DjATUit,Good. Here is a version of your script using arrays - it is much shorter: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=T:\icons\icandy Icons\iCandy Junior\The Icons\Home 2.ico #AutoIt3Wrapper_Res_Comment=This program speeds up the process of typing "Learning Objective" and "To be able to". By using Windows key and Alt followed by l or t #AutoIt3Wrapper_Res_Description=Speeding up typing at school! #AutoIt3Wrapper_Res_Fileversion=1.0 Beta #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> Global $HK_String[4], $HK_Check[4], $rdHKout[4], $Comboset1[4], $Comboset2[4], $Combosetletter[4], $InputHK[4] Opt("TrayMenuMode", 3) Global $SetKeyBoardShortcutsTray = TrayCreateItem("Set Keyboard Shortcuts") Global $EscScript = TrayCreateItem("Exit") HotKeySet("{ESCAPE}", "stoptxt") HotKeySet("#!l", "TypeLO") HotKeySet("#!t", "TYPEtbat") ; Create GUI Global $hMain_GUI = GUICreate("Control Panel for SchoolBoard", 482, 330, 302, 218) GUISetIcon("D:\005.ico") Global $PageControl1 = GUICtrlCreateTab(8, 8, 436, 256) Global $TabSheet1 = GUICtrlCreateTabItem("Keyboard Shortcuts") ; Create all 3 sets in one loop ; We use the loop counter ($i) to put the ControlIDs into the arrays we declared earlier ; We also use some simple maths to change the vertical position of the elements on each pass -> 56 + (60 * $i) For $i = 0 To 2 GUICtrlCreateLabel("First Key", 24, 56 + (60 * $i), 47, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Second Key", 104, 56 + (60 * $i), 63, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Letter", 191, 56 + (60 * $i), 32, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("Phrase/ Sentence", 260, 56 + (60 * $i), 84, 18) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Comboset1[$i + 1] = GUICtrlCreateCombo("Win", 24, 80 + (60 * $i), 49, 25) GUICtrlSetData(-1, "Alt|Ctrl") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 80, 80 + (60 * $i), 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") $Comboset2[$i + 1] = GUICtrlCreateCombo("Alt", 105, 80 + (60 * $i), 49, 25) GUICtrlSetData(-1, "Ctrl|Win") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("+", 170, 80 + (60 * $i), 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") $Combosetletter[$i + 1] = GUICtrlCreateCombo("a", 193, 80 + (60 * $i), 49, 25) GUICtrlSetData(-1, "b|c|d|e|f|g|h|i|j|k|m|n|o|p|q|r|s|u|v|w|x|y|z") GUICtrlSetFont(-1, 8, 400, 0, "Arial") GUICtrlCreateLabel("=", 249, 80 + (60 * $i), 13, 22) GUICtrlSetFont(-1, 12, 400, 0, "Arial") $InputHK[$i + 1] = GUICtrlCreateInput("Type your sentence here", 264, 80 + (60 * $i), 169, 22) GUICtrlSetFont(-1, 8, 400, 0, "Arial") Next GUICtrlCreateTabItem("") Global $hOK_Button = GUICtrlCreateButton("&OK", 166, 272, 75, 25) Global $hCancel_Button = GUICtrlCreateButton("&Cancel", 246, 272, 75, 25) Global $hHelp_Button = GUICtrlCreateButton("&Help", 328, 272, 75, 25) GUISetState(@SW_HIDE) While 1 ; Look for tray events Switch TrayGetMsg() Case $EscScript ; Exit script completely Exit Case $SetKeyBoardShortcutsTray ; Show the GUI so we can set HotKeys GUISetState(@SW_SHOW, $hMain_GUI) EndSwitch ; Look for GUI events Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $hCancel_Button ; Hide GUI again without changing HotKeys GUISetState(@SW_HIDE, $hMain_GUI) Case $hOK_Button ; Change HotKeys and then hide GUI again Change_HotKeys() GUISetState(@SW_HIDE, $hMain_GUI) Case $hHelp_Button ; Show some Help - I hope! EndSwitch WEnd Func Change_HotKeys() ; Reset HotKeys in turn ; We use the loop counter ($i) just as before - to identify which element of the array we want to use For $i = 1 To 3 ; Unset current key HotKeySet($HK_String[$i]) ; Now set HotKey string to blank $HK_String[$i] = "" ; Get character for first combo selection and add to string $HK_String[$i] &= Get_Char($Comboset1[$i]) ; Get character for second combo selection and add to string $HK_String[$i] &= Get_Char($Comboset2[$i]) ; Add key character to string $HK_String[$i] &= GUICtrlRead($Combosetletter[$i]) ; Set required phrase $rdHKout[$i] = GUICtrlRead($InputHK[$i]) ; Set check string $HK_Check[$i] = GUICtrlRead($Comboset1[$i]) & " - " & GUICtrlRead($Comboset2[$i]) & " - " & GUICtrlRead($Combosetletter[$i]) ; Set the new key HotKeySet($HK_String[$i], "UserHotKey" & $i) ; Note the use of the concatenation operator (&) to make a string which holds the correct hotkey number Next EndFunc Func Get_Char($Combo) Local $sRet ; Set value according to combo value Switch GUICtrlRead($Combo) Case "Alt" $sRet = "!" Case "Win" $sRet = "#" Case "Ctrl" $sRet = "^" EndSwitch ; Return value Return $sRet EndFunc Func stoptxt() Exit 0 EndFunc ;==>stoptxt Func UserHotKey1() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK_Check[1] & @CRLF & "Your Message Is: " & $rdHKout[1]) ; Send($rdHKout[1]) ; <<<<<<<<<<<<<<<< what you will need! EndFunc ;==>UserHotKey1 Func UserHotkey2() MsgBox(0, "Success", "Your new hot key 2 is: " & $HK_Check[2] & @CRLF & "Your Message Is: " & $rdHKout[2]) EndFunc ;==>UserHotkey2 Func UserHotkey3() MsgBox(0, "Success", "Your new hot key 1 is: " & $HK_Check[3] & @CRLF & "Your Message Is: " & $rdHKout[3]) EndFunc ;==>UserHotkey3 Func TypeLO() Send("Learning Objective") EndFunc ;==>TypeLO Func TYPEtbat() Send("To be able to") EndFunc ;==>TYPEtbatI have explained what is going on in the script - I hope you can follow.Now a simple question - which should pose you no difficulty at all - do you understand why the arrays are all declared with 4 elements (i.e. $aArray[4]) when there are only 3 HotKeys? M23Edit: Added script Edited December 13, 2009 by Melba23 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 Link to comment Share on other sites More sharing options...
meisandy Posted December 20, 2009 Author Share Posted December 20, 2009 sorry for slow reply thank-you 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