About detecting a key Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SkyLife
Posts: 19
Joined: 18 May 2017, 20:53

About detecting a key

23 Dec 2017, 06:37

I want to detect what key I pressed and execute the command when pressed, as listed below, but putting all the keys in it would require too many columns
UCR released by evilC has such a feature
https://autohotkey.com/boards/viewtopic.php?t=12249
I hope someone can help
Detecting all the keys on the keyboard is the best

Code: Select all

Gui, new
Gui +ToolWindow -Border
Gui, Font, S18
Gui, Add, Text, Center, Press the key
Gui, Show
Loop
{
	if getkeystate("A", "P" )
	{
	MsgBox you press "A"
	ExitApp
	}
	if getkeystate("B", "P" )
	{
	MsgBox you press "B"
	ExitApp
	}
}
return
.....
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: About detecting a key  Topic is solved

23 Dec 2017, 07:47

Why not hotkeys? (Edit: Oh, I just followed the link to EvilC's post. There's probably a way to query for pressed keys and get them all returned. But you might also be interested in the Input command, though it has some limitations.)

If you need hotkeys to all do the same thing, like literally telling you you pressed a particular key, see this code:

Code: Select all

Loop, 255
Hotkey, % "~" Format("vk{:x}",A_Index), pressed, On
return

pressed:
Tooltip % "You pressed "  GetKeyName(SubStr(A_ThisHotkey,2))
return
Edit: Based on EvilC's post, you might be able to make use of A_PriorKey and the use of A_TimeIdlePhysical or with Hotekys: A_PriorHotkey (or A_ThisHotkey if you incorporate it into the Hotkey's actions)and A_TimeSincePriorHotkey. The potential problem with using A_TimeIdlePhysical is that it responds to mouse movement.

Edit 2: And he linked his source code, so it would be worthwhile to check out his code to see what his implementation was to see if you can directly use that.
SkyLife
Posts: 19
Joined: 18 May 2017, 20:53

Re: About detecting a key

23 Dec 2017, 20:23

Thanks of your answer. This code help me a lot.
Althought it work well , there is a problem about this code.
Hotkey "DELETE", "END", and "PGDN"...are bound, but it can`t detect.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: About detecting a key

06 Jan 2018, 15:48

Huh, I'm at a loss as to why that is happening. I can confirm these keys that aren't producing characters are not working. One exception is backspace works for me. Oh, and the F1-F12 keys are still working for me. Looking at key history, they should be getting triggered. It could be other scripts interfering.

You may need to directly create these Hotkeys:

Code: Select all

Hotkey, Delete, pressed, On
Hotkey, End, pressed, On
Hotkey, PgDn, pressed, On
Hotkey, NumpadPgDn, pressed, On
Hotkey, NumpadEnd, pressed, On
Not that pretty unfortunately. Hopefully someone knows why this code that's supposed to make all the keys, based on their virtual key numbers, into hotkeys isn't working.
SkyLife
Posts: 19
Joined: 18 May 2017, 20:53

Re: About detecting a key

07 Jan 2018, 00:09

Well I think this question can only be solved by this method.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: metallizer, oktavimark, Rohwedder and 227 guests