Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
swdev:autohotkey:examples [2018/02/13 14:05]
smayr [Run Application]
swdev:autohotkey:examples [2018/02/13 17:37] (current)
smayr [Messages or Dialogs]
Line 34: Line 34:
 <code autoit> <code autoit>
 ; Click method: ; Click method:
-Click 310, 65   ; coordinates relative to Window+Click 310, 65               ; coordinates relative to Window
  
 ; MouseClick method: ; MouseClick method:
Line 44: Line 44:
  
 Menu, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x300 y15   ; coordinates relative to client Menu, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x300 y15   ; coordinates relative to client
 +</code>
 +
 +=== Keyboard ===
 +<code autoit>
 +Send, {LAlt}e               ; menu: <alt>E - Edit
 +Send, {LAlt down}e{LAlt up} ; menu: <alt>E - Edit
 +
 +; Ctrl-C to copy using Send
 +SetKeyDelay, 500, 500       ; delay after each keystroke sent by Send and ControlSend
 +Send, {ctrl down}c{ctrl up} ; Copy using send
 +
 +; Ctrl-C to copy using SendInput
 +SendInput {ctrl down}c{ctrl up}   
 +
 +; Ctrl-C to copy using ControlSend
 +ControlSend, , {ctrl down}c{ctrl up}, ahk_exe myapp.exe  
 +</code>
 +
 +=== Messages or Dialogs ===
 +Send a message with ''MsgBox'':
 +<code autoit>
 +; Format:
 +;   MsgBox, Text
 +;   MsgBox [, Options, Title, Text, Timeout]
 +MsgBox, 4, "Yes/No", "Do you want to continue?", 5   ; Yes/No dialog with 5 sec timeout
 +IfMsgBox No {
 +    return
 +}    
 +
 +; Show mouse coordinates
 +MouseGetPos, MouseX, MouseY
 +MsgBox The current mouse cursor position is X%MouseX% Y%MouseY%.
 +</code>
 +
 +Send a message with ''SplashTextOn'':
 +<code autoit>
 +; Format: 
 +;    SplashTextOn [, Width, Height, Title, Text]
 +SplashTextOn, , , Displays only a title bar.
 +Sleep, 2000
 +SplashTextOn, 400, 300, Clipboard, The clipboard contains:`n%clipboard%
 +WinMove, Clipboard, , 0, 0    ; Move the splash window to the top left corner.
 +MsgBox, Press OK to dismiss the SplashText
 +SplashTextOff
 +</code>
 +
 +Send a messag with ''ToolTip'':
 +<code autoit>
 +ToolTip, Hello World!!!, 100, 15    ; display ToolTip
 +Sleep, 5000                         ; pause program execution for 5 secs
 +ToolTip, , 100, 15                  ; clear ToolTip
 </code> </code>
  
Line 103: Line 154:
         ; MouseClick, left, 90, 65    ; Menu: Edit > Copy         ; MouseClick, left, 90, 65    ; Menu: Edit > Copy
                  
-    ;    sleep, 500 +    ;    Sleep, 500 
-    ;    ;send, {LAlt}e               ; menu: <alt>E - Edit +    ;    ;Send, {LAlt}e               ; menu: <alt>E - Edit 
-    ;    ;send, {LAlt down}e{LAlt up} ; menu: <alt>E - Edit +    ;    ;Send, {LAlt down}e{LAlt up} ; menu: <alt>E - Edit 
-    ;    ;sleep, 1000 +    ;    ;Sleep, 1000 
-    ;    ;send, e                     ; menu: <alt>E - Edit +    ;    ;Send, e                     ; menu: <alt>E - Edit 
-    ;    ;sleep, 1000 +    ;    ;Sleep, 1000 
-    ;    ;send, s                     ; menu option: Select All+    ;    ;Send, s                     ; menu option: Select All
     ;         ;    
-    ;    ; SetKeyDelay, 500, 500 +    ;    ; SetKeyDelay, 500, 500      ; delay after each keystroke sent by Send and ControlSend 
-    ;    ;send, {ctrl down}c{ctrl up}       ; Copy using send+    ;    ;Send, {ctrl down}c{ctrl up}       ; Copy using send
     ;    ;SendInput {ctrl down}c{ctrl up}   ; Copy using SendInput     ;    ;SendInput {ctrl down}c{ctrl up}   ; Copy using SendInput
     ;         ;    
-    ;    ; Display window name 
-    ;    WinGet, OutputVar, ProcessName 
-    ;    ;MsgBox, "ahk_exe emuapp32.exe" 
-    ;    ;ControlGetFocus, OutputVar 
-    ;    MsgBox, %OutputVar% 
                  
          
         ; --- Select All (using click on toolbar) ---         ; --- Select All (using click on toolbar) ---
-        SetControlDelay -1  +        SetControlDelay,   ; smallest possible delay 
-        ;ControlClickx300 y15, ahk_exe emuapp32.exe   ; client +        ControlClick, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x300 y15   ; coordinates relative to client 
-        ;ControlClick, x310 y65, ahk_exe emuapp32.exe,,,, NA    ; using relative coordinates +        Sleep500
-        ControlClick, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x305 y15   ; using relative coordinates +
-        sleep5000+
         if ErrorLevel  { ; i.e. it's not blank or zero.         if ErrorLevel  { ; i.e. it's not blank or zero.
-            MsgBox, The ControlClick for ToolbarWindow322 ... 'Select All' failed.+            ;MsgBox, The ControlClick for ToolbarWindow322 ... 'Select All' failed. 
 +            ToolTip, The ControlClick for ToolbarWindow322 ... 'Select All' failed., 100, 15
         } else {         } else {
-            MsgBox, The ControlClick for ToolbarWindow322 ... 'Select All' succeeded.+            ;MsgBox, The ControlClick for ToolbarWindow322 ... 'Select All' succeeded. 
 +            ToolTip, The ControlClick for ToolbarWindow322 ... 'Select All' succeeded., 100, 15
         }         }
         ; ;Click 310, 66         ; ;Click 310, 66
         ; MouseClick, left, 310, 65         ; MouseClick, left, 310, 65
-        ;sleep, 500 +        Sleep, 500 
-        ;Menu, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x305 y15   ; using relative coordinates+        ToolTip, , 100, 15  ; clear ToolTip 
 +        ;Menu, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x300 y15   ; coordinates relative to client
          
-        ; --- Copy (using click on toolbar) ---+        ; --- Copy to Clipboard (using click on toolbar) ---
         emptyClipboard()         emptyClipboard()
         ; ;ControlClick, x325 y15, ahk_exe emuapp32.exe   ; client         ; ;ControlClick, x325 y15, ahk_exe emuapp32.exe   ; client
-        ;ControlClick, x335 y70, ahk_exe emuapp32.exe,,,, NA    ; using relative coordinates+        ;ControlClick, x335 y70, ahk_exe emuapp32.exe,,,, NA    ; coordinates relative to client
         ;ControlClick, ToolbarWindow322, Click, 1,          ;ControlClick, ToolbarWindow322, Click, 1, 
-        ControlClick, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x230 y15   ; using relative coordinates+        ControlClick, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x230 y15   ; coordinates relative to client
         ; ;Click 335, 15         ; ;Click 335, 15
         ; MouseClick, left, 335, 15         ; MouseClick, left, 335, 15
-        sleep5000 +        Sleep500 
-        ; +         
         ; ;ControlSend, , {ctrl down}c{ctrl up}, ahk_exe emuapp32.exe           ; ;ControlSend, , {ctrl down}c{ctrl up}, ahk_exe emuapp32.exe  
 +        
 +        ; --- Copy to Clipboard (using Keyboard) ---
 +        ;copyToClipboard()
                  
         ; --- Clear Selection (using click on toolbar) ---         ; --- Clear Selection (using click on toolbar) ---
-        ;ControlClick, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x325 y15   ; using relative coordinates+        ;ControlClick, ToolbarWindow322, ahk_exe emuapp32.exe,,,, NA x325 y15   ; coordinates relative to client
                  
-        ; --- Copy to Clipboard --- +        ; --- Paste from Clipboard ---
-        ;copyToClipboard()+
         pasteFromClipboard()         pasteFromClipboard()
     } else {     } else {
Line 171: Line 220:
                  
         ; Display window name         ; Display window name
-        WinGet, OutputVar, ProcessName +        ;WinGet, OutputVar, ProcessName 
-        MsgBox, %OutputVar%+        ;MsgBox, %OutputVar%
                  
         ; Call File > New (using Mouse)         ; Call File > New (using Mouse)
Line 187: Line 236:
  
 ;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
-Paste data to clipboard+Empty clipboard
 ;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
-pasteFromClipboard()+emptyClipboard()
 { {
-    ;if WinExist("Untitled - Notepad") {   ; Select window using win name +    clipboard = Empty the clipboard
-    if WinExist("ahk_exe notepad.exe") {   ; Select window using app exe +
-        WinActivate ; use the window found above +
-        MsgBox Found Notepad +
-    } else { +
-        Run, Notepad.exe +
-        MsgBox Running Notepad +
-    } +
-    sleep, 500 +
-    ;Send, %clipboard%. +
-    ;SendInput, {ctrl down}v{ctrl up} +
-    send, {ctrl down}v{ctrl up}+
 } }
  
 ;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
-Paste data to clipboard+Copy data to clipboard
 ;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
 copyToClipboard() copyToClipboard()
Line 212: Line 250:
     emptyClipboard()     emptyClipboard()
     ;Send, ^c     ;Send, ^c
-    send, {ctrl down}c{ctrl up}+    Send, {ctrl down}c{ctrl up}
     ClipWait, 2     ClipWait, 2
     if ErrorLevel {     if ErrorLevel {
Line 222: Line 260:
  
 ;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
-Empty clipboard+Paste data from clipboard
 ;------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------
-emptyClipboard()+pasteFromClipboard()
 { {
-    clipboard = Empty the clipboard+    ;if WinExist("Untitled - Notepad") {   ; Select window using win name 
 +    if WinExist("ahk_exe notepad.exe") {   ; Select window using app exe 
 +        WinActivate ; use the window found above 
 +        MsgBox Found Notepad 
 +    } else { 
 +        Run, Notepad.exe 
 +        MsgBox Running Notepad 
 +    } 
 +    Sleep, 500 
 +    ;Send, %clipboard%. 
 +    ;SendInput, {ctrl down}v{ctrl up} 
 +    Send, {ctrl down}v{ctrl up}
 } }
  
Line 238: Line 287:
     ;MsgBox The color at the current cursor position is %color%.     ;MsgBox The color at the current cursor position is %color%.
     MsgBox The current mouse cursor position is X%MouseX% Y%MouseY%.     MsgBox The current mouse cursor position is X%MouseX% Y%MouseY%.
-  + 
 </code> </code>