You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Click命令内直接计算写法失效,如何修复?

Why Your First Two Click Syntax Fail & How to Fix Them

Hey there! Let's break down why those initial Click attempts didn't work, and walk through simple fixes for your AutoHotkey script.

The Root Cause: AHK's Traditional vs Expression Syntax

AutoHotkey commands (like Click) use traditional syntax by default for their parameters. Here's what that means for your code:

  • When you write %width%, it just replaces the variable with its raw value (e.g., if width=800, it becomes 800).
  • Any extra text after that (like - 30) is treated as plain, unprocessed text—not a math operation.

So your first attempt:

click, %width% - 30, %height% - 30

...actually sends the string 800 - 30 as the X-coordinate, not the calculated value 770. The Click command can't parse that messy string as a valid number, so it does nothing.

Your second try with parentheses:

click, (%width% - 30), (%height% - 30)

...still treats the whole thing as text ((800 - 30)), which is also not a valid coordinate. Parentheses don't trigger math in traditional syntax—they're just regular characters here.

Fixes You Can Use

Fix 1: Force Expression Mode for Click Parameters

You can tell AHK to treat the parameters as an expression by adding % (percent sign + space) before each calculation. This tells AHK to evaluate the math instead of treating it as text:

f1::
winGetActiveStats, title, width, height, topLeftX, topLeftY
click, % width - 30, % height - 30
return

This will correctly compute width-30 and height-30 as numeric coordinates.

Fix 2: Pre-Calculate Variables (Your Working Approach)

Your existing solution is totally valid and often easier to read, especially if you need to reuse the coordinates later:

f1::
winGetActiveStats, title, width, height, topLeftX, topLeftY
x := width - 30, y := height - 30
click, %x%, %y%
return

The := operator uses expression mode by default, so the math is calculated correctly here.

Quick Tip for Future Reference

  • Use %var% for simple variable substitution in traditional command parameters.
  • Use % expression when you need to do math, function calls, or other calculations in command parameters.
  • Use variable := expression for assignment statements (always uses expression mode).

内容的提问来源于stack exchange,提问作者john c. j.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:40:37