【问题标题】:AutoHotkey: calculating with mouse coordinates does not workAutoHotkey:用鼠标坐标计算不起作用
【发布时间】:2022-01-16 10:35:44
【问题描述】:

假设在单击并按住时,我想显示一个彩色框,它覆盖了单击和释放鼠标左键之间的区域。如果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

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    由于屏幕坐标可以为负,请使用abs()(docs) 将负宽度或高度设为正:
    Gui, Show, % "x" start_x "y" start_y "w" abs(end_x-start_x) "h" abs(end_y-end_x)

    【讨论】:

    • 谢谢!不幸的是,您发现的错字是通过复制引入的。但是由于您的建议,我发现应该使用绝对值,因为高度和宽度不能为负数。您能否编辑您的帖子并建议使用 abs(),以便对未来的读者有意义?
    • 是的,abs() 如果您使用负屏幕坐标会很好。我将在其中进行编辑。
    猜你喜欢
    • 1970-01-01
    • 2013-03-18
    • 2021-03-07
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    相关资源
    最近更新 更多