Input command with Function and Numpad Key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ardent246
Posts: 7
Joined: 22 Nov 2019, 16:35

Input command with Function and Numpad Key

25 Nov 2019, 10:57

Hi,

I am trying to use Input to detect function and numpad keys as it detects other keys. Input presents two problems: 1) it does not detect function keys; and 2) it detects numpad keys as if they were normal number keys (i.e., Numpad0 is recorded as 0 rather than as Numpad0).

There is an workaround if the input string includes only one function or numpad key:

Code: Select all

Input, SingleKey, L1,{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}{Numpad1}{Numpad2}{Numpad3}{Numpad4}{Numpad5}{Numpad6}{Numpad7}{Numpad8}{Numpad9}{NumpadDot}{NumpadDiv}{N;umpadMult}{NumpadSub}{NumpadAdd}
if (ErrorLevel <> "MAX")
{
	; MsgBox Early: "%SingleKey%"
	SingleKey := SingleKey . SubStr(ErrorLevel, 8, StrLen(ErrorLevel) - 7)
}
MsgBox "%SingleKey%"
My problem is that I would like to detect back to back function key or numpad key presses (e.g., {F5}{F5} to be recorded as F5F5 the way jj would). Is there a way for Input to accomplish this?

using the above code with L2 instead of L1 exits with the first press of a function or a numpad key.

Thanks!
joefiesta
Posts: 502
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Input command with Function and Numpad Key

25 Nov 2019, 12:05

Like you said, INPUT can't handle this. Period.

You could do it by creating a script with EVERY key you would want to capture defined as a hotkey. Each hotkey would grab the keyname and then you do what you want with that information.

All the hotkeys could execute the same code, for example:

Code: Select all

;
;   AHK Script to capture F1 - F12 keystrokes
;
Gui, add, text,, Enter the keystokes.  To stop entry,
Gui, add, text,,     Hit the ESCAPE key.
Gui, show, x100 y100, Key Entry Script
return
#IfWinActive, Key Entry Script
F1::
F2::
F3::
F4::
F5::
F6::
F7::
F8::
F9::
F10::
F11::
F12::
string := string . "ÿ" . a_ThisHotKey
return

Esc::
   OutString := StrReplace(string, "ÿ", " ")
   msgbox % "This keys you entered were:`n" Outstring
   return
ardent246
Posts: 7
Joined: 22 Nov 2019, 16:35

Re: Input command with Function and Numpad Key

25 Nov 2019, 13:33

Thanks, I was afraid this might be the case. Easy enough to implement though I was hoping for a more elegant solution!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 352 guests