GetKeyState("Insert", "T") returning wrong toggle state

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Scoox
Posts: 122
Joined: 11 May 2014, 09:12
Location: China

GetKeyState("Insert", "T") returning wrong toggle state

28 Jan 2019, 18:57

The following code doesn't always return the correct Insert key toggle state after switching between applications:

Code: Select all

~Insert::
	MsgBox % GetKeyState("Insert", "T")
Return
For instance, if I have two console windows, A & B, both initially with Insert mode turned off. Then I hit the Insert key while A is the active window. Now A is in Insert mode, while B remains in regular (non-insert) mode. Considering this is a per-window thing, what's the point of treating Insert as a toggle state?

Is there some sort of "global" insert state and applications are free to observe this state or keep their own internal state? CapsLock seems to work globally across all applications. Thanks!
swagfag
Posts: 4070
Joined: 11 Jan 2017, 17:59

Re: GetKeyState("Insert", "T") returning wrong toggle state

28 Jan 2019, 19:40

https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getkeystate
Retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).
on, off—alternating each time the key is pressed, this is the extent to which getkeystate will tell u if ur key is toggled
what it wont tell u, is whether whatever edit field, ur cursor happens to reside in, is in insert-mode. some edits dont even support insert-mode, for instance
User avatar
Scoox
Posts: 122
Joined: 11 May 2014, 09:12
Location: China

Re: GetKeyState("Insert", "T") returning wrong toggle state

28 Jan 2019, 19:46

Thanks swagfag. Was just googling this and this came up:
I note that the Insert key, unlike Caps-Lock and Num-Lock, does not have a systemwide state, and it varies per-application or even per-control. I believe (though am uncertain) that maintaining the state of the Insert key is your responsibility and that GetKeyState will not work as you intend with the Insert key in particular.
Which confirms what you say. Thanks for chiming in!

Return to “Ask For Help”

Who is online

Users browsing this forum: Damian01, Google [Bot], thebbandit and 45 guests