skjom Posted March 19, 2014 Posted March 19, 2014 Hi Ive just started using AutoIT and was trying to create a basic scrit but was having trouble getting started. Basically i wanted to: Press a key "P" If the onscreen keyboard in windows 7 x64 is not running then launch it If it is running then check the window state when the user Presses the key, if its mimimised then maximise it. If its maximised then minimise it. Trouble is i cant get the first section working where i try to launch it. Below is the code any Pointers would be good Opt("TrayIconHide", 1) ;0=show, 1=hide tray icon HotKeySet("p", "Actions") Func Actions() If NOT ProcessExists("OSK.exe") Then Run("OSK.exe", "", @SW_SHOWMAXIMIZED) Else Local $iState = WinGetState("On-Screen Keyboard") If ($iState, 16) Then WinSetState("On-Screen Keyboard","",@SW_MAXIMIZE) Else WinSetState("On-Screen Keyboard","",@SW_MINIMIZE ) EndIf ENDIf EndFunc
Valuater Posted March 19, 2014 Posted March 19, 2014 (edited) Syntax error I found... Change this line If $iState = 16 Then Also nee a loop Opt("TrayIconHide", 1) ;0=show, 1=hide tray icon HotKeySet("p", "Actions") HotKeySet("{ESC}", "Terminate") While 1 Sleep(20) WEnd Func Actions() If Not ProcessExists("OSK.exe") Then Run("OSK.exe", "", @SW_SHOWMAXIMIZED) Else Local $iState = WinGetState("On-Screen Keyboard") If $iState = 16 Then WinSetState("On-Screen Keyboard", "", @SW_MAXIMIZE) Else WinSetState("On-Screen Keyboard", "", @SW_MINIMIZE) EndIf EndIf EndFunc ;==>Actions Func Terminate() Exit 0 EndFunc ;==>Terminate Edited March 19, 2014 by Valuater
somdcomputerguy Posted March 19, 2014 Posted March 19, 2014 @SW_SHOWMAXIMIZED should be @SW_SHOWMAXIMIZE. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
jdelaney Posted March 19, 2014 Posted March 19, 2014 (edited) You need a loop HotKeySet("p", "Actions") Func Actions() If NOT ProcessExists("OSK.exe") Then Run("OSK.exe", "", @SW_SHOWMAXIMIZED) Else If BitAND(WinGetState("On-Screen Keyboard"), 16) Then WinSetState("On-Screen Keyboard","",@SW_MAXIMIZE) Else WinSetState("On-Screen Keyboard","",@SW_MINIMIZE ) EndIf ENDIf EndFunc While True WEnd WinGetState shows the summation of all states on the window...BitAND checks if your specific state is present, or not. Edited March 19, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Moderators Melba23 Posted March 19, 2014 Moderators Posted March 19, 2014 jdelaney,Please put a Sleep in that loop - or offer to pay for the new CPU. 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
Valuater Posted March 19, 2014 Posted March 19, 2014 @ SDguy @SW_SHOWMAXIMIZED should be correct @ jd That loop will burn the processor, needs a sleep 8)
jdelaney Posted March 19, 2014 Posted March 19, 2014 (edited) Yes it will ...too lazy to add in those 20 or so characters edit: 8 or so characters...still too lazy Edited March 19, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
somdcomputerguy Posted March 19, 2014 Posted March 19, 2014 @ SDguy @SW_SHOWMAXIMIZED should be correct Ah, I see now. So it should. Both are listed on this page - http://www.autoitscript.com/autoit3/docs/macros.htm, but on this page - http://www.autoitscript.com/autoit3/docs/functions/Run.htm, only the maximize flag is listed, which is what I went by. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
skjom Posted March 19, 2014 Author Posted March 19, 2014 okay thanks the main problem i have is that i cant launch the onscreen keyboard at all, when i press the key "p" nothing happens Func Actions() If Not ProcessExists("OSK.exe") Then Run("OSK.exe", "", @SW_SHOWMAXIMIZED)
somdcomputerguy Posted March 19, 2014 Posted March 19, 2014 When I run this line - Run("OSK.exe", "", @SW_SHOWMAXIMIZED), I get a dialog box that says, "Could not start On-Screen Keyboard". - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
skjom Posted March 19, 2014 Author Posted March 19, 2014 When I run this line - Run("OSK.exe", "", @SW_SHOWMAXIMIZED), I get a dialog box that says, "Could not start On-Screen Keyboard". what system are you running on. I get nothing back. The rest works now as i want, when i press the key it maximises and minimises but i cant lauch the onscreen keyboard at all. I am on WIN7 x64 HotKeySet("{F3}", "Actions") HotKeySet("{ESC}", "Terminate") While 1 Sleep(20) WEnd Func Actions() If Not ProcessExists("OSK.exe") Then Run("OSK.exe", "", @SW_SHOWMAXIMIZED) Else Local $iState = WinGetState("On-Screen Keyboard") If BitAND(WinGetState("On-Screen Keyboard"), 16) Then WinSetState("On-Screen Keyboard","",@SW_RESTORE) Else WinSetState("On-Screen Keyboard", "", @SW_MINIMIZE) EndIf EndIf EndFunc ;==>Actions Func Terminate() Exit 0 EndFunc ;==>Terminate
somdcomputerguy Posted March 19, 2014 Posted March 19, 2014 Win7 HP x64. I also tried to run my snippet script while logged into an Admin account, and then a regular account. Same issue both times. I don't know why the message appears, or how to work around it, but I'm sure somebody here will be able to help you. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
skjom Posted March 19, 2014 Author Posted March 19, 2014 Win7 HP x64. I also tried to run my snippet script while logged into an Admin account, and then a regular account. Same issue both times. I don't know why the message appears, or how to work around it, but I'm sure somebody here will be able to help you. okay thanks ill try digging into it more
skjom Posted March 19, 2014 Author Posted March 19, 2014 okay edited the script, now the OSK launches but the minimise or maximise doesnt function: Opt("TrayIconHide", 1) ;0=show, 1=hide tray icon HotKeySet("{F3}", "Actions") HotKeySet("{ESC}", "Terminate") While 1 Sleep(20) WEnd Func Actions() If Not ProcessExists("OSK.exe") Then ShellExecuteWait(@SystemDir & "\osk.exe") Else Local $iState = WinGetState("On-Screen Keyboard") If BitAND(WinGetState("On-Screen Keyboard"), 16) Then WinSetState("On-Screen Keyboard","",@SW_RESTORE) Else WinSetState("On-Screen Keyboard", "", @SW_MINIMIZE) EndIf EndIf EndFunc ;==>Actions Func Terminate() Exit 0 EndFunc ;==>Terminate
MaxG Posted March 20, 2014 Posted March 20, 2014 skjom, Do you have a windows key on your keyboard? I'm running Win7 x64 and this works for me just fine, including the minimize/maximize requirement. Opt("TrayIconHide", 1) ;0=show, 1=hide tray icon HotKeySet("{F3}", "Actions") HotKeySet("{ESC}", "Terminate") While 1 Sleep(20) WEnd Func Actions() If Not ProcessExists("OSK.exe") Then ;NOTE: Replace {LWIN} with {RWIN} if your keyboard is different. (Assuming yours HAS a windows key) Send("{LWIN}OSK{ENTER}") Else Local $iState = WinGetState("On-Screen Keyboard") If BitAND(WinGetState("On-Screen Keyboard"), 16) Then WinSetState("On-Screen Keyboard","",@SW_RESTORE) Else WinSetState("On-Screen Keyboard", "", @SW_MINIMIZE) EndIf EndIf EndFunc ;==>Actions Func Terminate() Exit 0 EndFunc ;==>Terminate
reb Posted March 20, 2014 Posted March 20, 2014 Yes it will ...too lazy to add in those 20 or so characters edit: 8 or so characters...still too lazy Maybe this will help REB expandcollapse popup#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** _Singleton("MyTools") #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <GUIConstants.au3> #include <Misc.au3> #include <WinAPI.au3> #include <StringSize.au3> Opt("GUICloseOnESC", 1) HotKeySet("^+p","Protect") Global Const $SC_DRAGMOVE = 0xF012 Global $menuit[10] Global $Accumulate = "", $Count = 0, $Dick = "", $file = "", $file2 = 0, $i = 0, $Trys = 0, $St $GuiWidth = 500 ;400 $Title = "DICK'S NEW TOOLS" $hGUI = GUICreate($Title, $GuiWidth, 20,370 , 24, $WS_POPUP, $WS_EX_TOPMOST) ;$WS_EX_TOOLWINDOW)) ; 386 $filemenu = GUICtrlCreateMenu("Array Display") $menuit[0] = GUICtrlCreateMenuItem("Array Display Below Highlited Variable", $filemenu) $menuit[1] = GUICtrlCreateMenuItem("Delete All Arrays", $filemenu) $msg = GUICtrlCreateMenu("Message Box") $menuit[2] = GUICtrlCreateMenuItem("Message Box Below Highlited Variable", $msg) $menuit[3] = GUICtrlCreateMenuItem("Delete All Message Boxs", $msg) $Slp = GUICtrlCreateMenu("Sleep (10)") $menuit[4] = GUICtrlCreateMenuItem("Add Sleep below Selected Line", $Slp) $Region = GUICtrlCreateMenu("#Region - ") $menuit[5] = GUICtrlCreateMenuItem("Add #Region - below Selected Line", $Region) $menuit[6] = GUICtrlCreateMenuItem("Add #EndRegion - below Selected Line", $Region) $con = GUICtrlCreateMenu("ConsoleWrite") $menuit[7] = GUICtrlCreateMenuItem("Add ConsoleWrite below Selected Item", $con) $Clp = GUICtrlCreateMenu("Clip Board") $menuit[8] = GUICtrlCreateMenuItem("Clear Clip Board", $clp) GUISetState(@SW_SHOW) While 1 ; Adds white space to each end of title $Title = " " & $Title & " " ; Get width of title $aRet = _StringSize($Title) If $aRet[2] > $GuiWidth Then ; If now too large, remove last added spaces $Title = StringTrimLeft(StringTrimRight($Title, 1), 1) ExitLoop EndIf WEnd ;~ ; Set title WinSetTitle($hGUI, "", $Title) Do $msg = GUIGetMsg() Switch $msg Case $menuit[0] ArrayDisplay() Case $menuit[1] DeleteAllArrays() Case $menuit[2] MsBox() Case $menuit[3] StartUp2() ;DelAllMsBox() Case $menuit[4] Slp10() Case $menuit[5] RegionWrite() Case $menuit[6] RegionEndWrite() Case $menuit[7] ConWrt() Case $menuit[8] Clpclear() Case $GUI_EVENT_PRIMARYDOWN _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch Until $msg = $GUI_EVENT_CLOSE WinActivate($file) Exit Func ArrayDisplay() ClipPut("") ; Empty Clip board $file = "" $file = WinGetTitle("[CLASS:SciTEWindow]") WinActivate($file) Send("^c") ; Put onto Clip board $Var = ClipGet(); Read Clip coard If StringMid($Var, 1, 1) <> "$" Then ; Read from line count 1 (Beginning) MsgBox(64, "", "Must Select a Variable first", 2) Return EndIf $Dick = '_ArrayDisplay(' & $Var & ',"' & $Var & '")' ClipPut($Dick) WinActivate($file) Send("{HOME}") Send("{END}") ; Fiind End of Line Send("{ENTER}") Send("{HOME}") ; Make a line below Send("^v") Send("{ALT}{DOWN}s") Send("^s") ; Put into file so Functions can read if not previously saved ; Put into file so Functions can read if not previously saved EndFunc ;==>ArrayDisplay Func DeleteAllArrays() Dim $Accumulate = "", $Count = 0, $Dick = "", $file = "", $file2 = 0, $i = 0, $Trys = 0 StartUp() ;~ WinActivate($file) EndFunc ;==>DeleteAllArrays Func StartUp() ; DELETE ARRAY $file = WinGetTitle("[CLASS:SciTEWindow]") WinActivate($file) Send("^s") $Count = StringInStr($file, "-") $file2 = StringLeft($file, $Count - 2) $Dick = FileRead($file2) $Array = StringSplit($Dick, @CR) For $i = 1 To UBound($Array) - 1 If StringInStr($Array[$i], "_Array") <> 2 Then $Accumulate = $Accumulate & $Array[$i] & @CR EndIf Next $Accumulate = StringTrimRight($Accumulate, 1) Check() ;~ Send("^s") ; Put into file so Functions can read if not previously saved EndFunc ;==>StartUp Func Check() ; DELETE ARRAYD If $Accumulate = "" Then $Trys += 1 If $Trys = 3 Then MsgBox(64, "", "Try Again") Return EndIf If $Accumulate = "" Then StartUp() EndIf WriteNewText() EndFunc ;==>Check #Region ; New Test Func WriteNewText() ; DELETE ARRAYD WinActivate($file) ClipPut($Accumulate) Send("^a") Send("^v") Send("^s") ; Put into file so Functions can read if not previously saved EndFunc ;==>WriteNewText Func MsBox() ClipPut("") $file = WinGetTitle("[CLASS:SciTEWindow]") WinActivate($file) Send("^c") $Var = ClipGet() If StringMid($Var, 1, 1) <> "$" Then MsgBox(64, "", "Must Select a Variable first", 2) Return EndIf $Dick = 'MsgBox(0,' & $Var & ',"' & $Var & '")' ClipPut($Dick) WinActivate($file) Send("{HOME}") Send("{END}") Send("{ENTER}") Send("{HOME}") Send("^v") Send("{ALT}{DOWN}s") Send("^s") ; Put into file so Functions can read if not previously saved EndFunc ;==>MsBox ;~ Func DelAllMsBox() ;~ StartUp2() ;~ EndFunc ;==>DelAllMsBox Func StartUp2() ; DELETE MsgBox Dim $Accumulate = "", $Count = 0, $Dick = "", $file = "", $file2 = 0, $i = 0, $Trys = 0 $file = WinGetTitle("[CLASS:SciTEWindow]") WinActivate($file) Send("^s") $Count = StringInStr($file, "-") $file2 = StringLeft($file, $Count - 2) $Dick = FileRead($file2) $Array = StringSplit($Dick, @CR) For $i = 1 To UBound($Array) - 1 If StringInStr($Array[$i], "Msgbox") <> 2 Then $Accumulate = $Accumulate & $Array[$i] & @CR EndIf Next $Accumulate = StringTrimRight($Accumulate, 1) Check2() EndFunc ;==>StartUp2 Func Check2() If $Accumulate = "" Then $Trys += 1 If $Trys = 3 Then MsgBox(64, "", "Try Again") Return EndIf If $Accumulate = "" Then StartUp() EndIf WriteNewText2() EndFunc ;==>Check2 Func WriteNewText2() WinActivate($file) ClipPut($Accumulate) Send("^a") Send("^v") Send("^s") ; Put into file so Functions can read if not previously saved EndFunc ;==>WriteNewText2 Func Slp10() $file = WinGetTitle("[CLASS:SciTEWindow]") WinActivate($file) $Dick = "Sleep(10)" ClipPut($Dick) ;~ sleep(10) Send("{HOME}") ;~ Sleep(100) Send("{END}") ;~ Sleep(100) Send("{ENTER}") Send("{HOME}") ;~ Sleep(60); 50 Send("^v") Send("{ALT}{DOWN}s") Send("^s") ; Put into file so Functions can read if not previously saved ; Put into file so Functions can read if not previously saved EndFunc ;==>Slp10 Func RegionWrite() $file = WinGetTitle("[CLASS:SciTEWindow]") $Dick = "#Region - " ClipPut($Dick) WinActivate($file) Send("{HOME}") Send("{END}") ; Fiind End of Line Send("{ENTER}") Send("{HOME}") ; Make a line below Send("^v") Send("{ALT}{DOWN}s") Send("^s") ; Put into file so Functions can read if not previously saved ; Put into file so Functions can read if not previously saved EndFunc ;==>RegionWrite Func RegionEndWrite() $file = WinGetTitle("[CLASS:SciTEWindow]") $Dick = "#EndRegion - " ClipPut($Dick) WinActivate($file) Send("{HOME}") Send("{END}") ; Fiind End of Line Send("{ENTER}") Send("{HOME}") ; Make a line below Send("^v") Send("{ALT}{DOWN}s") Send("^s") ; Put into file so Functions can read if not previously saved ; Put into file so Functions can read if not previously saved EndFunc ;==>RegionWrite Func ConWrt() ConsoleWrite('@@ (120) :(' & @MIN & ':' & @SEC & ')ConWrt()' & @CR) ;### Function Trace ClipPut("") $file = WinGetTitle("[CLASS:SciTEWindow]") WinActivate($file) Send("^c") $Var = ClipGet() If StringMid($Var, 1, 1) <> "$" Then MsgBox(64, "", "Must Select a Variable first", 2) Return EndIf ; wORKING COPY $Dick ='ConsoleWrite(' & $Var & ' & ' & '" = ' & $Var & '" & @CRLF)' $Dick = 'ConsoleWrite(' & $Var & ' & ' & '" = ' & $Var & '" & @CRLF)' ClipPut($Dick) WinActivate($file) Send("{HOME}") Send("{END}") Send("{ENTER}") Send("{HOME}") Send("^v") Send("{ALT}{DOWN}s") Send("^s") ; Put into file so Functions can read if not previously saved EndFunc ;==>ConWrt Func Clpclear() ClipPut("") EndFunc Func Protect() Send(" ;* Protected") EndFunc #Region - End of File MEASURE TWICE - CUT ONCE
water Posted March 20, 2014 Posted March 20, 2014 BTW: Could you please give a meaningful title to your threads? Everyone on this forum has a questions - that's what the forum is made for skjom 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
somdcomputerguy Posted March 20, 2014 Posted March 20, 2014 okay edited the script, now the OSK launches but the minimise or maximise doesnt function. I noticed you're using the ShellExecuteWait function to start OSK. That function will do what it's meant to do, then wait until the specified program ends before letting the script continue with whatever is left. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
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