AutoHotkey:用鼠标坐标计算不起作用
AutoHotkey: calculating with mouse coordinates does not work
假设在单击并按住时,我想显示一个彩色框,它覆盖单击和释放鼠标左键之间的区域。如果按住 Ctrl
并显示包含覆盖区域的工具提示,以下简单脚本会跟踪鼠标在单击和释放时的位置。仅当我为框指定固定大小时才显示框:
但是,如果我尝试计算框的大小(取消注释最后一行代码),大多数时候 没有显示框?
Ctrl & LButton::
MouseGetPos, start_x, start_y
Keywait, LButton
MouseGetPos, end_x, end_y
; show coordinates for debugging
ToolTip % "dx: " . end_x-start_x . "`ndy: " . end_y-start_y
Gui, -Caption -Border +AlwaysOnTop
Gui, Color, red
; fixed size works ...
Gui, Show, % "x" start_x "y" start_y "w" 100 "h" 10
; ... but the following doesnt work
;Gui, Show, % "x" start_x "y" start_y "w" end_x-start_x "h" end_y-start_y
由于屏幕坐标可以为负,使用abs()
(docs)使负宽度或正高度:
Gui, Show, % "x" start_x "y" start_y "w" abs(end_x-start_x) "h" abs(end_y-end_x)
假设在单击并按住时,我想显示一个彩色框,它覆盖单击和释放鼠标左键之间的区域。如果按住 Ctrl
并显示包含覆盖区域的工具提示,以下简单脚本会跟踪鼠标在单击和释放时的位置。仅当我为框指定固定大小时才显示框:
但是,如果我尝试计算框的大小(取消注释最后一行代码),大多数时候 没有显示框?
Ctrl & LButton::
MouseGetPos, start_x, start_y
Keywait, LButton
MouseGetPos, end_x, end_y
; show coordinates for debugging
ToolTip % "dx: " . end_x-start_x . "`ndy: " . end_y-start_y
Gui, -Caption -Border +AlwaysOnTop
Gui, Color, red
; fixed size works ...
Gui, Show, % "x" start_x "y" start_y "w" 100 "h" 10
; ... but the following doesnt work
;Gui, Show, % "x" start_x "y" start_y "w" end_x-start_x "h" end_y-start_y
由于屏幕坐标可以为负,使用abs()
(docs)使负宽度或正高度:
Gui, Show, % "x" start_x "y" start_y "w" abs(end_x-start_x) "h" abs(end_y-end_x)