Can someone help me understand "~", "*" syntax from 'while getkeystate ' statement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
saspoon
Posts: 5
Joined: 03 Apr 2018, 00:48

Can someone help me understand "~", "*" syntax from 'while getkeystate ' statement

27 Apr 2018, 18:06

Code: Select all

~LButton::
    MouseGetPos, begin_x, begin_y
    while GetKeyState("LButton")
    {
        MouseGetPos, x, y
        ToolTip, % begin_x ", " begin_y "`n" Abs(begin_x-x) " x " Abs(begin_y-y)
        Sleep, 10
    }
    ToolTip
return
(1) Bitwise-not (~): This inverts each bit of its operand. If the operand is a floating point value, it is truncated to an integer prior to the calculation. If the operand is between 0 and 4294967295 (0xffffffff), it will be treated as an unsigned 32-bit value. Otherwise, it is treated as a signed 64-bit value. For example, ~0xf0f evaluates to 0xfffff0f0 (4294963440).

(2) Dereference (*): *Expression assumes that Expression resolves to a numeric memory address; it retrieves the byte at that address as a number between 0 and 255 (0 is always retrieved if the address is 0; but any other invalid address must be avoided because it might crash the script). However, NumGet() generally performs much better when retrieving binary numbers.

--------

I found out that without "~" syntax, the code above doesn't work. And I found out that adding "*" (~*Lbutton) :: allows Lbutton inputs within multiple keystroke combination to be detected i.e. Lbutton input from Ctrl+Lbutton, Ctrl+Shift+Lbutton.

I think I only have very limited knowledge about this. Can someone help me understand the two (1) (2), from the official AHK manuals.
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: Can someone help me understand "~", "*" syntax from 'while getkeystate ' statement

27 Apr 2018, 19:16

Context is the key... the parts (1) Bitwise-not and (2) Dereference you quoted are from the page Variables and Expressions, section Operators in Expressions (https://autohotkey.com/docs/Variables.htm#Operators) - a bit advanced stuff.

They have absolutely nothing to do with the use of * and ~ when defininig hotkeys. A hotkey definition is not an expression.

When defining hotkeys, * and ~ have a special meaning: https://autohotkey.com/docs/Hotkeys.htm:
* Wildcard: Fire the hotkey even if extra modifiers are being held down.[...]
[...]
~ When the hotkey fires, its key's native function will not be blocked (hidden from the system).
[...]
Read more on the linked page.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Can someone help me understand "~", "*" syntax from 'while getkeystate ' statement

28 Apr 2018, 19:28

I collected a list of various character uses here:
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mstrauss2021, Spawnova, william_ahk, zephyrus2706 and 353 guests