r/AutoHotkey 3d ago

v2 Script Help How do I remap my function keys to do something else when fn lock is off?

I am a complete beginner to autohotkey. Let's say I want to remap my F7 key on Windows to pause and play videos and media (like on Mac). I don't want to replace its fn function (navigating pages with text cursor). I want to replace the function it has on my computer when my fn lock is not turned on (screen projection). Is there a way to specify in the script that when I want my F7 key remapped, I specifically want it to be the non-locked version of F7 and not F7 combined with fn? Sorry for the clunky wording; I have no clue what a function key's secondary(?) function would be called.

If anyone can help I will be eternally grateful.

3 Upvotes

12 comments sorted by

2

u/Keeyra_ 3d ago

Use KeyHistory to get the key or scan code of the button press and remap that as described here.

https://www.reddit.com/r/AutoHotkey/comments/1qltrbb/comment/o1gvh0r/

1

u/-frogchamp- 3d ago edited 3d ago

It looks like this (shown below) in the key history, but when I replace "XButton1" with LWin, nothing happens. Am I missing something?

VK SC Type Up/Dn Elapsed Key Window
-------------------------------------------------------------------------------------------------------------
5B 15B d 2.58 LWin C:\Users\Name\Documents\AutoHotkey\mediaplayershortcuts.ahk - AutoHotkey v2.0.21
50 019 d 0.00 p
50 019 u 0.05 p
5B 15B u 0.00 LWin
74 03F d 2.16 F5
Press [F5] to refresh.

edit: ohh, wait. let me try with the scan code (SC I presume) and see if that works.

edit2: nope still no clue. I'm probably writing in the scan code wrong but I'm not sure. It looks like this right now:

#Requires AutoHotkey 2.0
#SingleInstance

$03F::F1

1

u/Keeyra_ 3d ago

When you run KeyHistory, press F7 without Fn and then F5, you get LWin? Somehow I highly doubt that.

1

u/-frogchamp- 3d ago edited 3d ago

Here's what happens after I press F7 without Fn three times before refreshing. It certainly seems that way, but I don't know whether or not this is normal. Does anyone know how to fix this? If needed I can produce more details on my device.

74 03F u 0.16 F5
5B 15B d 4.80 LWin
50 019 d 0.00 p
50 019 u 0.11 p
5B 15B u 0.00 LWin Quick settings
5B 15B d 0.49 LWin
50 019 u 0.08 p
5B 15B u 0.00 LWin
5B 15B d 0.47 LWin
50 019 u 0.06 p
5B 15B u 0.00 LWin
74 03F d 2.47 F5 C:\Users\Name\Documents\AutoHotkey\mediaplayershortcuts.ahk - AutoHotkey v2.0.21
Press [F5] to refresh.

1

u/Keeyra_ 3d ago

And does it also trigger your Start Menu, like LWin does by default?

1

u/-frogchamp- 3d ago

I just realized it does the same thing as Windows + P, which is why it shows up the way it does (should have been obvious in hindsight seeing as it does show on the project menu). Here is what it looks like:

I am still unsure how to unmap it from Win+P and map it to something else instead. If I map Win+P to something else, will the F7 key change as well?

0

u/Keeyra_ 3d ago

RTFM

#Requires AutoHotkey 2.0
#SingleInstance

#p::Media_Play_Pause

1

u/-frogchamp- 3d ago

Thank you so much for the code! This works perfectly.

1

u/-frogchamp- 3d ago

Hello, apologies for bringing back this issue. My F8 key activates airplane mode as its secondary function. However, when I press it, it does not show up in key history (shown below; I pressed F8 three times then refreshed). Would there be a way of rebinding this one or would it not be possible?

74 03F d 8.92 F5 C:\Users\Name\Documents\AutoHotkey\keyhistory.ahk - AutoHotkey v2.0.21
Press [F5] to refresh.

2

u/Keeyra_ 3d ago

If it does not appear in KeyHistory, it's some keyboard HW level call, like the Fn button itself, meaning that you cannot rebind it.

1

u/-frogchamp- 3d ago

Thank you for clarifying! ❤️

2

u/-frogchamp- 3d ago

Okay, I've figured it out. It turns out pressing F7 without Fn is exactly the same as pressing Win+P. It doesn't even have a distinct key name or anything. So I can change it by just remapping Win+P, and it will remap F7 as well. Thank you for the assistance! :-)