How can I find the scan code for a non-standard key Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
John in NZ
Posts: 3
Joined: 09 Jun 2023, 22:15

How can I find the scan code for a non-standard key

Post by John in NZ » 10 Jun 2023, 01:34

Hi folks,

I'm very new to AutoHotkey, so as a start I've got an otherwise acceptable keyboard (HP 320 wired keyboard) which has a [Print] key located immediately above the backspace key, so being the sloppy typist I am, I'm forever hitting the Print key ... :oops:

This keyboard has a load of functions assigned to the Function keys which are accessed by pressing the Fn with the F key - for instance [Fn] + [F2] = [Sleep] - that's way harder to explain that it is to do!

What I would like to do is re-assign the [Print] hotkey to [Fn] + [Print], so I can't hit it accidentally and not have to cancel the Print dialogue box, and whilst I'm at it, I might as well reassign the un modified [Print] key to [Backspace].

So, my question is, how can I achieve this?

I know that these keys will have a scan code, but I don't know the name of the key to use the GetKeySC() or GetKeyName()

emp00
Posts: 147
Joined: 15 Apr 2023, 12:02

Re: How can I find the scan code for a non-standard key

Post by emp00 » 10 Jun 2023, 05:34

Hi @John in NZ -- here you can find the HOTWO-instructions: https://www.autohotkey.com/docs/v1/KeyList.htm#SpecialKeys

Actually, I have exactly the same keyboard and would be interested if you could post your success with the task at hand. My conclusion so far was, that autohotkey cannot detect the Fn and other special keys because they're handled by a special driver (not via the operating system standards). I also tried to find a tool or driver information for this HP keyboard but no luck! Let us know, please.

User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: How can I find the scan code for a non-standard key  Topic is solved

Post by mikeyww » 10 Jun 2023, 07:21

There might be a BIOS setting or keyboard utility to swap the default for Fn. The Fn key is not usually accessible to programs like AHK.

viewtopic.php?p=394008#p394008

viewtopic.php?f=76&t=81807

viewtopic.php?p=367333#p367333

viewtopic.php?t=59644

emp00
Posts: 147
Joined: 15 Apr 2023, 12:02

Re: How can I find the scan code for a non-standard key

Post by emp00 » 10 Jun 2023, 09:40

See above, this is about the "HP 320 wired keyboard" -> it's a wired USB keyboard thus no BIOS option for this. Regular PC, no Notebook.

Apparently, also no HP utility or even driver available: https://support.hp.com/us-en/product/hp-wired-desktop-320k-keyboard/37676399/more-options

emp00
Posts: 147
Joined: 15 Apr 2023, 12:02

Re: How can I find the scan code for a non-standard key

Post by emp00 » 10 Jun 2023, 14:43

I gave it another shot, enabling "InstallKeybdHook" and checking if any scancodes are detected as per @mikeyww 's instructions here.

Result:
- Clearly, the Fn key from this HP keyboard does bypass the system and thus does not generate a scancode detectable by Autohotkey :-(
- Even pressing a Fn combination like Fn F8 (Printscreen) does not show up in the KeybdHook list!
- However, Windows does recognize these special keys and the functionality behind does work even though I have no HP driver installed...

Maybe @John in NZ (greetings to this great country!!) has more time and luck, would be highly appreciated to find a solution.

John in NZ
Posts: 3
Joined: 09 Jun 2023, 22:15

Re: How can I find the scan code for a non-standard key

Post by John in NZ » 10 Jun 2023, 16:01

Thanks for the replies so far guys ... I think the answer to my question is the KeybdHook function ... :)

However, thanks for going into a bit more detail for me, I'm sure it will get me on the right track ... :superhappy:

@emp00 as you say, HP don't offer any utility software or drivers for this keyboard, which does seem strange given the other support options they provide for other devices, and I'll certainly post a reply here if I do manage to come up with a fix ... :thumbup:

@mikeyww thanks for saving me some time with tracking down the scan code for the Fn

You probably recognise that my comments in the initial post should be considered as aspirational rather than cast in tablets of stone, but for others who may not grasp what I'm trying to achieve.

Firstly, my prevent accidental key strokes from generating a result that actually gives me more work to do. As a follow on "would be nice" I'd like to use the key, rather than leave it as a dead key.

Again, thanks for the replies, I'll check them out after my Sunday morning coffee kicks in ... :D

emp00
Posts: 147
Joined: 15 Apr 2023, 12:02

Re: How can I find the scan code for a non-standard key

Post by emp00 » 10 Jun 2023, 16:17

@John in NZ As already mentioned above: With KeybdHook I could not detect any scancode from the Fn key (either alone or in combination with other keys). Please let me know if I'm wrong... I wonder how Windows can detect these keys - and why can't Autohotkey? Any solution to bring the HP special "Fn" key(s) to a better use with AHK is much appreciated. After all, it's just a "super-simple standard" USB keyboard, no strings and no Notebook attached.

John in NZ
Posts: 3
Joined: 09 Jun 2023, 22:15

Re: How can I find the scan code for a non-standard key

Post by John in NZ » 10 Jun 2023, 19:45

emp00 wrote:
10 Jun 2023, 16:17
... I could not detect any scancode from the Fn key ...
@emp00 I had a quick look at what's going on using KeyInFormer, and as you say, the fn key doesn't generate a scan code when pressed singly, or in conjunction with any other modifier key. How or why things are done this way is beyond me, but if someone has an idea of what's going on I'd love to hear.

However, what KeyInFormer *IS* telling me is that the irritating Print button generates p on the key press and L Ctrl on the key release, this behaviour has been mapped to the modifier key behaviour too. The separate p and L Ctrl must be combined because of the way the switch de-bounce software handles things.

As I said, I'm very new to AHK, so you may know if AHK can modify the key press and key release behaviour, but that's beyond me for the moment, so over to you ... again ... :)

emp00
Posts: 147
Joined: 15 Apr 2023, 12:02

Re: How can I find the scan code for a non-standard key

Post by emp00 » 11 Jun 2023, 07:30

@John in NZ Actually, I never understood your initial problem with the "Print" key above "Backspace". In case you accidentally hit this key, it's actually "F12" being executed and if this is a problem, you can easily use AHK to reassign F12. The "Print" function is only executed if you press "Fn / F12" - but this should never happen accidentally when using "Backspace", right? Sorry for the stupid question :-)

By the way, you're referring to "KeyInFormer" - what exactly is this? Googling this it could be a separate utility? Why that instead of simply using the "built-in" AHK functionality as explained above / click here? Looking at your results I think all is correct but I just wondered.

Unfortunately, we probably have to live with the situation AHK being unable to detect user-defined "Fn" key combinations. Have you asked HP support if there's a secret special utility available to configure the HP special keys for the HP 320 wired keyboard?

Post Reply

Return to “Ask for Help (v2)”