Skip to content

Commit

Permalink
Add Click
Browse files Browse the repository at this point in the history
not part of 1.0.24 spec but common and useful enough to add it now
  • Loading branch information
phil294 committed Jul 20, 2023
1 parent 76f9db6 commit 2dec99d
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 14 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AHK_X11 can be used completely without a terminal. You can however if you want u
<details><summary><strong>CLICK TO SEE WHICH COMMANDS ARE IMPLEMENTED AND WHICH ARE MISSING</strong>. Note however that this is not very representative. For example, no `Gui` sub command is included in the listing. For a better overview on what is already done, skim through the <a href="https://phil294.github.io/AHK_X11"><b>FULL DOCUMENTATION HERE</b></a>.</summary>

```diff
DONE ?% (94/219):
DONE ?% (94/220):
+ Else, { ... }, Break, Continue, Return, Exit, GoSub, GoTo, IfEqual, Loop, SetEnv, Sleep, FileCopy,
+ SetTimer, WinActivate, MsgBox, Gui, SendRaw, #Persistent, ExitApp,
+ EnvAdd, EnvSub, EnvMult, EnvDiv, ControlSendRaw, IfWinExist/IfWinNotExist, SetWorkingDir,
Expand All @@ -71,11 +71,11 @@ DONE ?% (94/219):
+ WinGet, Input, Loop (parse a string), ToolTip, If var [not] in/contains MatchList, ControlSetText,
+ PixelSearch, #Include, InputBox

NEW 4% (8/219): (not part of spec or from a more recent version)
@@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, @@
NEW ?% (9/220): (not part of spec or from a more recent version)
@@ Echo, ahk_x11_print_vars, FileRead, RegExGetPos, RegExReplace, EnvGet, Click @@
@@ ahk_x11_track_performance_start, ahk_x11_track_performance_stop @@

REMOVED 5% (12/219):
REMOVED ?% (12/220):
# ### Those that simply make no sense in Linux:
# EnvSet, EnvUpdate, PostMessage, RegDelete, RegRead, RegWrite, SendMessage, #InstallKeybdHook,
# #InstallMouseHook, #UseHook, Loop (registry)
Expand All @@ -84,7 +84,7 @@ REMOVED 5% (12/219):
# AutoTrim: It's always Off. It would not differentiate between %a_space% and %some_var%.
# It's possible but needs significant work.

TO DO ?% (101/219): alphabetically
TO DO ?% (101/220): alphabetically
- BlockInput, ClipWait, Control, ControlFocus, ControlGet, ControlGetFocus,
- ControlMove,
- DetectHiddenText, DetectHiddenWindows, Drive, DriveGet, DriveSpaceFree,
Expand Down
85 changes: 84 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ <h2>Table of contents </h2>
<li>
<a href="#ControlClick.htm">ControlClick</a>
</li>
<li>
<a href="#Click.htm">Click</a>
</li>
<li>
<a href="#MouseClick.htm">MouseClick</a>
</li>
Expand Down Expand Up @@ -2407,6 +2410,10 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<td height="16" class="calibre4"><a href="#Menu.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Menu</a></td>
<td height="16" class="calibre4">Creates, deletes, modifies and displays menus and menu items. Changes the tray icon and its tooltip. Controls whether the main window of a compiled script can be opened. </td>
</tr>
<tr class="calibre3">
<td height="16" class="calibre4"><a href="#Click.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">Click</a></td>
<td height="16" class="calibre4">Clicks or holds a mouse button, or turns the mouse wheel.</td>
</tr>
<tr class="calibre3">
<td height="16" class="calibre4"><a href="#MouseClick.htm" class="pcalibre3 pcalibre1 pcalibre calibre5 pcalibre2">MouseClick</a></td>
<td height="16" class="calibre4">Clicks or holds a mouse button, or turns the mouse wheel.</td>
Expand Down Expand Up @@ -10459,7 +10466,7 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
<div class="calibreEbookContent">
<a id="MouseClick.htm" href="#MouseClick.htm">#</a> <h2 class="calibre17">MouseClick</h2>
<hr size="2" class="calibre24" />
<p class="calibre8">Clicks or holds a mouse button, or turns the mouse wheel.</p>
<p class="calibre8">Clicks or holds a mouse button, or turns the mouse wheel. Note: The <a href="#Click.htm">Click</a> command is generally more flexible and easier to use.</p>
<table cellspacing="5" width="100%" class="calibre28">
<tbody class="calibre2">
<tr class="calibre3">
Expand Down Expand Up @@ -10533,6 +10540,82 @@ <h2 class="calibre9"><span class="calibre23">The "Last Found" Window </span></h2
</pre>
</div>
</div>
<div class="calibreMain">
<div class="calibreEbookContent">
<a id="Click.htm" href="#Click.htm">#</a> <h2 class="calibre17">Click</h2>
<hr size="2" class="calibre24" />
<p class="calibre8">Clicks a mouse button at the specified coordinates. It can also hold down a mouse button, turn the mouse wheel, or move the mouse.</p>
<table cellspacing="5" width="100%" class="calibre28">
<tbody class="calibre2">
<tr class="calibre3">
<td height="48" class="calibre4">Click [, Options]</td>
</tr>
</tbody>
</table>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Parameters</strong></p>
<dl>
<dt>Options</dt>
<dd>
<p>If blank or omitted, a single left click is performed at the mouse cursor's current position. Otherwise, specify one or more of the following components: <var>Coords</var>, <var>WhichButton</var>, <var>ClickCount</var>, <var>DownOrUp</var>, and/or <var>Relative</var>. Separate each component from the next with at least one space, tab, and/or comma. The components can appear in any order except <var>ClickCount</var>, which must occur somewhere to the right of <var>Coords</var>, if present.</p>
<p><strong>Coords:</strong> If omitted, the cursor's current position is used. Otherwise, specify the X and Y coordinates to which the mouse cursor is moved prior to clicking. For example, <code>Click, 100 200</code> clicks the left mouse button at a specific position. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that.</p>
<p><strong>WhichButton:</strong> If omitted, it defaults to Left (the left mouse button). Otherwise, specify Left, Right, Middle (or just the first letter of each of these); or X1 (fourth button) or X2 (fifth button). For example, <code>Click, Right</code> clicks the right mouse button at the mouse cursor's current position. <span class="rm">Unlike <a href="MouseClick.htm">MouseClick</a>, the left and right buttons behave consistently across all systems, even if the user has swapped the buttons via the system's control panel.</span></p>
<p><var>WhichButton</var> can also be WheelUp or WU to turn the wheel upward (away from you), or WheelDown or WD to turn the wheel downward (toward you). <span class="ver">[v1.0.48+]</span>: WheelLeft (or WL) or WheelRight (or WR) may also be specified (but they have no effect on older operating systems older than Windows Vista). <em>ClickCount</em> is the number of notches to turn the wheel. However, some applications do not obey a <var>ClickCount</var> value higher than 1 for the mouse wheel. For them, use the Click command multiple times by means such as <a href="Loop.htm">Loop</a>.</p>
<p><strong>ClickCount:</strong> If omitted, it defaults to 1. Otherwise, specify the number of times to click the mouse button or turn the mouse wheel. For example, <code>Click, 2</code> performs a double-click at the mouse cursor's current position. If <var>Coords</var> is specified, <var>ClickCount</var> must appear after it. Specify zero (0) to move the mouse without clicking; for example, <code>Click, 100 200 0</code>.</p>
<p><strong>DownOrUp:</strong> If omitted, each click consists of a down-event followed by an up-event. Otherwise, specify the word Down (or the letter D) to press the mouse button down without releasing it. Later, use the word Up (or the letter U) to release the mouse button. For example, <code>Click, Down</code> presses down the left mouse button and holds it.</p>
<p><strong>Relative:</strong> If omitted, the X and Y coordinates will be used for absolute positioning. Otherwise, specify the word Rel or Relative to treat the coordinates as offsets from the current mouse position. In other words, the cursor will be moved from its current position by X pixels to the right (left if negative) and Y pixels down (up if negative).</p>
</dd>
</dl>
<p class="calibre8"> </p>
<p class="calibre8"><strong class="calibre14">Remarks</strong></p>
<p class="rm">The Click command is generally preferred over <a href="#MouseClick.htm">MouseClick</a> because it automatically compensates if the user has swapped the left and right mouse buttons via the system's control panel.</p>
<p class="rm">The Click command uses the sending method set by <a href="#SendMode.htm">SendMode</a>. To override this mode for a particular click, use a specific Send command in combination with <a href="#Send.htm#Click">{Click}</a>, as in this example: <code>SendEvent {Click 100 200}</code>.</p>
<p>To perform a shift-click or control-click, <a href="#Send.htm#Click">clicking via Send</a> is generally easiest. For example:</p>
<pre>Send +{Click 100 200} <em>; Shift+LeftClick</em>
Send ^{Click 100 200 Right} <em>; Control+RightClick</em></pre>
<p>Unlike <a href="#Send.htm">Send</a>, the Click command does not automatically release the modifier keys (Ctrl, Alt, Shift, and Win). For example, if <kbd>Ctrl</kbd> is currently down, <code>Click</code> would produce a control-click but <code>Send {Click}</code> would produce a normal click.</p>
<p class="rm">The <a href="#SendMode.htm">SendPlay mode</a> is able to successfully generate mouse events in a broader variety of games than the other modes. In addition, some applications and games may have trouble tracking the mouse if it moves too quickly, in which case <a href="#SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> can be used to reduce the speed (but only in <a href="#SendMode.htm">SendEvent mode</a>).</p>
<p>The <a href="#BlockInput.htm">BlockInput</a> command can be used to prevent any physical mouse activity by the user from disrupting the simulated mouse events produced by the mouse commands. However, this is generally not needed for the <a href="#SendMode.htm">SendInput</a> and <a href="#SendMode.htm">SendPlay</a> modes because they automatically postpone the user's physical mouse activity until afterward.</p>
<p>There is an automatic delay after every click-down and click-up of the mouse (except for <a href="#SendMode.htm">SendInput mode</a> and for turning the mouse wheel). Use <a href="#SetMouseDelay.htm">SetMouseDelay</a> to change the length of the delay.</p>
<h2 id="Related">Related</h2>
<p><a href="#Send.htm#Click">Send {Click}</a>, <a href="#SendMode.htm">SendMode</a>, <a href="#CoordMode.htm">CoordMode</a>, <a href="#SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>, <a href="#SetMouseDelay.htm">SetMouseDelay</a>, <a href="#MouseClick.htm">MouseClick</a>, <a href="#MouseClickDrag.htm">MouseClickDrag</a>, <a href="#MouseMove.htm">MouseMove</a>, <a href="#ControlClick.htm">ControlClick</a>, <a href="#BlockInput.htm">BlockInput</a></p>
<h2 id="Examples">Examples</h2>
<div class="ex" id="ExBasic">
<p><a class="ex_number"></a> Clicks the left mouse button at the mouse cursor's current position.</p>
<pre>Click</pre>
</div>

<div class="ex" id="ExCoord">
<p><a class="ex_number"></a> Clicks the left mouse button at a specific position.</p>
<pre>Click, 100 200</pre>
</div>

<div class="ex" id="ExCoordMove">
<p><a class="ex_number"></a> Moves the mouse cursor to a specific position without clicking.</p>
<pre>Click, 100 200 0</pre>
</div>

<div class="ex" id="ExCoordRight">
<p><a class="ex_number"></a> Clicks the right mouse button at a specific position.</p>
<pre>Click, 100 200 Right</pre>
</div>

<div class="ex" id="ExDouble">
<p><a class="ex_number"></a> Performs a double-click at the mouse cursor's current position.</p>
<pre>Click, 2</pre>
</div>

<div class="ex" id="ExDown">
<p><a class="ex_number"></a> Presses down the left mouse button and holds it.</p>
<pre>Click, Down</pre>
</div>

<div class="ex" id="ExUp">
<p><a class="ex_number"></a> Releases the right mouse button.</p>
<pre>Click, Up Right</pre>
</div>
</div>
</div>
<div class="calibreMain tbd">
<div class="calibreEbookContent">
<a id="MouseClickDrag.htm" href="#MouseClickDrag.htm">#</a> <h2 class="calibre17">MouseClickDrag</h2>
Expand Down
32 changes: 32 additions & 0 deletions src/cmd/x11/mouse/click.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "./mouse-click"

# Click [, Options]
# Not part of 1.0.24!
class Cmd::X11::Mouse::Click < Cmd::X11::Mouse::MouseClick
def self.min_args; 0 end
def self.max_args; 1 end
def run(thread, args)
mouse_click_args = Array(::String).new(7){""}
ints = [] of ::String
(args[0]? || "").split.each do |param|
case param.downcase
when "l","r","left","right","m","middle","xbutton1","xbutton2","x1","x2","wheelup","wu","wheeldown","wd","wheelleft","wl","wheelright","wr"
mouse_click_args[0] = param
when "down","up","d","u"
mouse_click_args[5] = param[0].to_s
when "rel","relative"
mouse_click_args[6] = "r"
else
ints << param if param.to_i?
end
end
if ints.size == 1
mouse_click_args[3] = ints[0]
elsif ints.size >= 2
mouse_click_args[1] = ints[0]
mouse_click_args[2] = ints[1]
mouse_click_args[3] = ints[2]? || ""
end
parse_run(thread, mouse_click_args)
end
end
13 changes: 8 additions & 5 deletions src/cmd/x11/mouse/mouse-click.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class Cmd::X11::Mouse::MouseClick < Cmd::Base
def self.min_args; 1 end
def self.max_args; 7 end
def run(thread, args)
parse_run(thread, args)
end
protected def parse_run(thread, args)
button = case args[0].downcase
when "right", "r" then XDo::Button::Right
when "middle", "m" then XDo::Button::Middle
Expand Down Expand Up @@ -33,12 +36,12 @@ class Cmd::X11::Mouse::MouseClick < Cmd::Base
end
relative = args[6]?.try &.downcase == "r"
thread.runner.display.pause do
if relative
thread.runner.display.x_do.move_mouse x, y
else
thread.runner.display.x_do.move_mouse x, y, screen
end
count.times do
if relative
thread.runner.display.x_do.move_mouse x, y
else
thread.runner.display.x_do.move_mouse x, y, screen
end
thread.runner.display.x_do.mouse_down button if ! up
thread.runner.display.x_do.mouse_up button if ! down
end
Expand Down
8 changes: 5 additions & 3 deletions src/util/ahk-string.cr
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ class Util::AhkString
word += char
end
end
down = word.downcase
ret[down] = ret[part[0].downcase.to_s] = {
n: n.to_i64?(prefix: true) || nil,
n = n.to_i64?(prefix: true)
key = word.downcase
key = n.to_s if key.empty? && n
ret[key] = ret[part[0].downcase.to_s] = {
n: n,
v: part[1..]? || "",
minus: minus,
plus: plus
Expand Down

0 comments on commit 2dec99d

Please sign in to comment.