0

I'd like to Use Win+Alt+<arrow-keys> to move current active window around. So I come up with Autohotkey script:

WinMoveRelative(rx, ry)
{
    ; Move current window by a relative rx, ry value. rx, ry can be positive or negative
    WinGetPos, x, y, width, height, A
    absx := x + rx
    absy := y + ry
    WinMove, A, , %absx%, %absy%
}
;
g_moveunit := 20
!#Left::  WinMoveRelative(0-%g_moveunit%, 0)  ; DON'T WORK
!#Right:: WinMoveRelative(%g_moveunit%, 0)    ; DON'T WORK
!#Up::    WinMoveRelative(0, -20)     ; works
!#Down::  WinMoveRelative(0, 20)      ; works

I just can't figure out how to pass g_moveunit and its negative value to the function. Please help.

Autohotkey v1.1.13.01

2
  • 1
    Don't enclose g_moveunit in percent signs (%); it's an expression! Rule of thumb: When working with pure numbers or passing something to a function, it's an expression.
    – MCL
    Jan 9, 2014 at 18:16
  • You're right, thanks. Please write it as answer. And I find that g_moveunit:=20 has to appear before any hotkey definition, otherwise, g_moveunit will always be empty value.
    – Jimm Chen
    Jan 10, 2014 at 13:14

1 Answer 1

1

Don't enclose g_moveunit in percent signs (%); it's an expression. Rule of thumb: When working with pure numbers or passing something to a function, it's an expression.

[Side note] To your other problem described in your comment:
Read the FAQ, respectively the explanation of the auto-execute section.

2
  • Thank you so much. I'm feeling lucking to get this answer with merely 8 views during two whole days.
    – Jimm Chen
    Jan 11, 2014 at 14:15
  • @JimmChen The AHK docs/FAQs are a great place to find answers. Try reading there next time and you may not have to sweat it out here ;)
    – MCL
    Jan 11, 2014 at 14:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .