Skip to content

Commit

Permalink
add Window Spy
Browse files Browse the repository at this point in the history
all done with AHK code!
  • Loading branch information
phil294 committed Nov 13, 2022
1 parent c5a1dd9 commit f2c43b2
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 4 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Features:
- [x] GUIs (partially done)
- [x] One-click compile script to portable stand-alone executable
- [x] Scripting: labels, flow control: If/Else, Loop
- [ ] Window Spy
- [x] Window Spy
- [x] Graphical installer (optional)
- [x] Context menu and compilation just like on Windows

Expand Down Expand Up @@ -132,11 +132,13 @@ There are different ways to use it.
1. The graphical way, like on Windows: Running the program directly opens up the interactive installer.
- Once installed, all `.ahk` files are associated with AHK_X11, so you can simply double click them.
- Also adds the Compiler into `Open as...` Menus.
- Also adds Window Spy to your applications.
2. Command line: Pass the script to execute as first parameter, e.g. `./ahk_x11 "path to your script.ahk"`
- Once your script's auto-execute section has finished, you can also execute arbitrary single line commands in the console. Code blocks aren't supported yet in that situation. Those single lines each run in their separate threads, which is why variables like `%ErrorLevel%` will always be `0`.
- When you don't want to pass a script, you can specify `--repl` instead (implicit `#Persistent`).
- If you want to pass your command from stdin instead of file, do it like this: `./ahk_x11 /dev/stdin <<< 'MsgBox'`.
- Compile scripts with `./ahk_x11 --compile "path/script.ahk"
- Compile scripts with `./ahk_x11 --compile "path/script.ahk"`
- Run Window Spy with `./ahk_x11 --windowspy`
- Hashbang supported if first line starts with `#!`

### Caveats
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ <h2 class="calibre18">Tutorial Contents</h2>
<p class="calibre8">Keystrokes are sent to the active (foremost) window by using the <a href="#Send.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Send</a> command. In the following example, Win+S becomes a hotkey to type a signature. Be sure that a window such as an editor or draft e-mail message is active before pressing the hotkey:<br class="calibre12" /> #s::<br class="calibre12" /> Send, Sincerely,{enter}John Smith<br class="calibre12" /> return</p>
<p class="calibre8">In the above example, all characters are sent literally except {enter} (which results in a simulated press of the Enter key). The next example illustrates some of the other commonly used special characters:<br class="calibre12" /> Send, ^c!{tab}pasted:^v</p>
<p class="calibre8">The above example sends a Control+C followed by an Alt+Tab followed by the string "pasted:" followed by a Control+V. See the <a href="#Send.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Send</a> command for a complete list of special characters and keys. </p>
<p class="calibre8"><u class="calibre20"><strong class="calibre14">Mouse Clicks</strong></u><strong class="calibre14">:</strong> To send a mouse click to a window it is first necessary to determine the X &amp; Y coordinates where the click should occur. This can be done with either AutoScriptWriter or Window Spy, <span class="tbd">which are included with AutoHotkey</span>. The following steps apply to the Window Spy method:</p>
<p class="calibre8"><u class="calibre20"><strong class="calibre14">Mouse Clicks</strong></u><strong class="calibre14">:</strong> To send a mouse click to a window it is first necessary to determine the X &amp; Y coordinates where the click should occur. This can be done with <span class="rm">either AutoScriptWriter or</span> <span class="x11">Window Spy, which is included with AutoHotkey</span>. The following steps apply to the Window Spy method:</p>
<ol class="calibre19">
<li class="calibre11">Launch Window Spy from the program's tray-icon menu or the Start Menu.</li>
<li class="calibre11">Activate the window of interest either by clicking its title bar, alt-tabbing, or other means (Window Spy will stay "always on top" by design).</li>
Expand Down
4 changes: 3 additions & 1 deletion src/ahk_x11.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ if ARGV[0]?
puts "AHK_X11 version: #{version}\nTargets to partially implement Classic Windows AutoHotkey specification: v1.0.24 (2004). AutoHotkey is a scripting language."
::exit
elsif ARGV[0] == "-h" || ARGV[0] == "--help"
puts "AHK_X11 is a Linux implementation for AutoHotkey classic version 1.0.24 (2004). Current version: #{version}. Full up to date documentation can be found at https://phil294.github.io/AHK_X11/.\n\nPossible methods of invocation:\n\nahk_x11 \"path to script.ahk\"\nahk_x11 /dev/stdin <<< $'MsgBox, 1\\nMsgBox, 2'\nahk_x11 --repl\nAlternatively, just run the program without arguments to open the graphical installer. Once installed, you should be able to run and/or compile any .ahk file in your file manager by selecting it from the right click context menu."
puts "AHK_X11 is a Linux implementation for AutoHotkey classic version 1.0.24 (2004). Current version: #{version}. Full up to date documentation can be found at https://phil294.github.io/AHK_X11/.\n\nPossible methods of invocation:\n\nahk_x11 \"path to script.ahk\"\nahk_x11 /dev/stdin <<< $'MsgBox, 1\\nMsgBox, 2'\nahk_x11 --repl\nahk_x11 --windowspy\nAlternatively, just run the program without arguments to open the graphical installer. Once installed, you should be able to run and/or compile any .ahk file in your file manager by selecting it from the right click context menu."
::exit
elsif ARGV[0] == "--repl"
lines = ["#Persistent"]
elsif ARGV[0] == "--windowspy"
lines = {{ read_file("./src/window-spy.ahk").split("\n") }}
elsif ARGV[0] == "--compile"
build_error "Syntax: ahk_x11 --compile FILE_NAME [OUTPUT_FILENAME]" if ARGV.size < 2
Compiler.new.compile(filename_to_path(ARGV[1]), ARGV[2]? ? filename_to_path(ARGV[2]) : nil)
Expand Down
11 changes: 11 additions & 0 deletions src/installer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ FileAppend, Comment=%app_comment% - this is the compiler to create stand-alone b
RunWait, desktop-file-install --dir=%A_Home%/.local/share/applications %app_name%-compiler.desktop
FileDelete, %app_name%-compiler.desktop

FileAppend, [Desktop Entry]`n, %app_name%-windowspy.desktop
FileAppend, Name=Window Spy`n, %app_name%-windowspy.desktop
FileAppend, Exec=%binary_path% --windowspy`n, %app_name%-windowspy.desktop
FileAppend, Icon=application-x-%app_name%`n, %app_name%-windowspy.desktop
FileAppend, Terminal=false`n, %app_name%-windowspy.desktop
FileAppend, Type=Application`n, %app_name%-windowspy.desktop
FileAppend, Categories=`n, %app_name%-windowspy.desktop
FileAppend, Comment=%app_comment% - tool to help with %app_name% scripting.`n, %app_name%-windowspy.desktop
RunWait, desktop-file-install --dir=%A_Home%/.local/share/applications %app_name%-windowspy.desktop
FileDelete, %app_name%-windowspy.desktop

RunWait, update-desktop-database %A_Home%/.local/share/applications
RunWait, xdg-mime default %app_name%.desktop application/x-%app_name%

Expand Down
82 changes: 82 additions & 0 deletions src/window-spy.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#Persistent

frozen = 0

Gui, Add, Text, x5 y5, Window Title, Class and Process:
Gui, Add, Edit, x5 y25 h65 w320 r3 vgui_win
Gui, Add, Text, x5 y95, Mouse Position:
Gui, Add, Edit, x5 y115 h65 w320 r3 vgui_mouse
Gui, Add, Text, x5 y185, Focused Control:
Gui, Add, Edit, x5 y205 h105 w320 r3 vgui_control
Gui, Add, Text, x5 y315, Active Window Position:
Gui, Add, Edit, x5 y335 h45 w320 r3 vgui_win_pos
Gui, Add, Text, x5 y385, Status Bar Text:
Gui, Add, Edit, x5 y405 h45 w320 r3 vgui_status_bar
Gui, Add, Text, x5 y455, Visible Text:
Gui, Add, Edit, x5 y475 h45 w320 r3 vgui_visible_text
Gui, Add, Text, x5 y525, All Text:
Gui, Add, Edit, x5 y545 h45 w320 r3 vgui_all_text
Gui, Add, Text, x5 y595 vgui_frozen, (Win+A to freeze display)
Gui, Show,, Window Spy

SetTimer, Clock, 500

Return

~#a::
if frozen = 0
{
GuiControl, , gui_frozen, FROZEN (Win+A to unfreeze)
frozen = 1
} else {
GuiControl, , gui_frozen, (Win+A to freeze display)
frozen = 0
}
return

GuiClose:
ExitApp

Clock:
if frozen = 1
Return
WinGet, win_id, ID, A
WinGetTitle, win_title, ahk_id %win_id%
if win_title = Window Spy
Return
WinGetClass, win_class, ahk_id %win_id%
WinGetPos, win_x, win_y, win_w, win_h, ahk_id %win_id%
WinGetText, win_txt, ahk_id %win_id%
MouseGetPos, mouse_x_win, mouse_y_win
CoordMode, Mouse
MouseGetPos, mouse_x_screen, mouse_y_screen
ctrl_nn =
win_right = win_x
win_right += %win_w%
win_bottom = win_y
win_bottom += %win_h%
if mouse_x_win >= 0
if mouse_y_win >= 0
if mouse_x_win < %win_right%
if mouse_y_win < %win_bottom%
MouseGetPos, , , , ctrl_nn
PixelGetColor, pixel_color, %mouse_x_win%, %mouse_y_win%, RGB
StringMid, pixel_color_r, pixel_color, 1, 2
StringMid, pixel_color_g, pixel_color, 3, 2
StringMid, pixel_color_b, pixel_color, 5, 2
ctrl_x =
ctrl_y =
ctrl_w =
ctrl_h =
ctrl_txt =
if ctrl_nn <>
{
ControlGetPos, ctrl_x, ctrl_y, ctrl_w, ctrl_h, %ctrl_nn%, ahk_id %win_id%
ControlGetText, ctrl_txt, %ctrl_nn%, ahk_id %win_id%
}
GuiControl, , gui_win, %win_title%`nahk_class %win_class%
GuiControl, , gui_mouse, Screen:`t`t%mouse_x_screen%, %mouse_y_screen% (less often used)`nColor:`t`t%pixel_color% (Red=%pixel_color_r% Green=%pixel_color_g% Blue=%pixel_color_b%)`nWindow:`t%mouse_x_win%, %mouse_y_win% (default)
GuiControl, , gui_control, ClassNN:`t%ctrl_nn%`n`tText:`t%ctrl_txt%`nPos:`t`tx: %ctrl_x%`ty: %ctrl_y%`tw: %ctrl_w%`th: %ctrl_h%
GuiControl, , gui_win_pos, x: %win_x%`ty: %win_y%`tw: %win_w%`th: %win_h%
GuiControl, , gui_visible_text, %win_txt%
Return

0 comments on commit f2c43b2

Please sign in to comment.