Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AutoHotKey script that remaps the F1-F12 function keys on the Microsoft Sculpt Mobile keyboard to be pressed without having to use the Fn key. Disables some of the Windows 8 shortcuts, but leaves media keys intact.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#InstallKeybdHook
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; OPTIONAL: For those who use Home/End more than PgUp/PgDown, this flips their use with the Fn key.
; If you want the buttons to function as they are, add a semicolon (;) to the beginning of each line below.
Home::PgUp
End::PgDn
PgUp::Home
PgDn::End
; F1 key by default, Fn+F1 is now Play/Pause
MEDIA_PLAY_PAUSE::F1
F1::MEDIA_PLAY_PAUSE
; F2 key by default, Fn+F2 is now Mute/Unmute
VOLUME_MUTE::F2
F2::VOLUME_MUTE
; F3 key by default, Fn+F3 is now Volume Down
VOLUME_DOWN::F3
F3::VOLUME_DOWN
; F4 key by default, Fn+F4 is now Volume Up
VOLUME_UP::F4
F4::VOLUME_UP
; F5 key by default, Fn+F5 does nothing
SendInput {F5}
+#F21::
return
; F6 key by default, Fn+F6 does nothing
!#F21::
SendInput {F6}
return
; F7 key by default, Fn+F7 does nothing
^#F21::
SendInput {F7}
return
; F8 key by default, Fn+F8 does nothing
#F21::
SendInput {F8}
return
; F9 key by default, Fn+F9 does nothing
^#BS::
SendInput {F9}
return
; F10 key by default, Fn+F10 does nothing
^#TAB::
SendInput {F10}
return
; F11 key by default, Fn+F11 does nothing
!#F22::
SendInput {F11}
return
; F12 key by default, Fn+F12 does nothing
^#F23::
SendInput {F12}
return
@kylemartin87

This comment has been minimized.

Copy link

commented Jul 18, 2014

I was shocked when I discovered this design flaw in my new Microsoft Sculpt Mobile Keyboard. So glad to find your AutoHotKey script that makes it all better again :)

@kylemartin87

This comment has been minimized.

Copy link

commented Jul 18, 2014

@tehshane: While using the script I noticed what appears to be a bug. The F5 key doesn't work. I think you need to swap lines 30 and 31.

@efendikaptan

This comment has been minimized.

Copy link

commented Aug 4, 2014

With klemartin87's revision, this works like a charm. Thank you both!

@lbleon

This comment has been minimized.

Copy link

commented Sep 1, 2014

Hi @tehshane,
This script is working fine on Windows 8, but in Windows 7 there are something wrong with F5-F12.
I'm trying to fix it.
How do you get the value like "^#F21" ? I think may be the value is different on Windows 8 and Windows 7.

@BenKewell

This comment has been minimized.

Copy link

commented Oct 28, 2014

There's a typo in the F5 key section, the commands are swapped in order.
Correct one should be this:

; F5 key by default, Fn+F5 does nothing
+#F21::
SendInput {F5}
return

@BenKewell

This comment has been minimized.

Copy link

commented Oct 28, 2014

Also as a remark, if anyone wants to hide the tray icon of the script or compiled EXE,
add this line to the file:

NoTrayIcon

@sasha14

This comment has been minimized.

Copy link

commented Nov 14, 2014

Tell me how to run this script? I made an extension file for the Microsoft Sculpt Mobile Keyboard Remap.cmd and ran it as administrator. But it did not help. I have windows 8.1 64
Tell me how that should be done?

@GuillaumeCombot

This comment has been minimized.

Copy link

commented Jan 12, 2015

thanks a lot!

@ekache

This comment has been minimized.

Copy link

commented Jan 13, 2015

@sasha14

try adding the script to the default autohotkeys.ahk file instead of creating one; worked for me.

@vbauerster

This comment has been minimized.

Copy link

commented Mar 8, 2015

I have an older revision of the same keyboard (called MS 6000 mobile), where fn + Del fires Insert key. I'd like to swap this combination, i.e. pressing Del to fire Ins, and vice versa.
I have tried:
del::ins
ins::del
but this didn't work.
Can please someone share his/her experience, how to obtain a secret code of a key? Like +#F21 for F5.

@linzuyi

This comment has been minimized.

Copy link

commented Oct 20, 2015

; F5 key by default, Fn+F5 does nothing
+#F21::
SendInput {F5}
return

@vcx

This comment has been minimized.

Copy link

commented Nov 4, 2015

@vbauerster Have you found a way to work around the ins-del thing on this keyboard? I'm also looking for a solution to the same problem...

@n0m0r3pa1n

This comment has been minimized.

Copy link

commented Nov 18, 2015

Is there any way I can run this on Ubuntu 14.04? I got the keyboard as a present and I like it, but it is really sad how the functions keys are working.

@wingsergey

This comment has been minimized.

Copy link

commented Dec 23, 2015

@tehshane
So how to run it on Windows7 ?

@wingsergey

This comment has been minimized.

Copy link

commented Dec 23, 2015

ok, found answer myself

http://ahkscript.org/

@GlynRD

This comment has been minimized.

Copy link

commented Feb 26, 2016

I have lost the plot! All I want to do is to map F2 to rename and F3 to next (i suspect that these are Windows functions)
The script above doesn't do this and anything I try does not work.
What syntax do I need to use to make this work, please?
TIA
Glyn

@VirtualSim

This comment has been minimized.

Copy link

commented Nov 25, 2016

Does not work for CodeGear C++ Builder

@liuning0820

This comment has been minimized.

Copy link

commented Mar 18, 2017

Good job, I solved my issue refer to your share. thanks a lot.

@DawnSaviours

This comment has been minimized.

Copy link

commented Jan 16, 2018

Many, many thanks, very happy fingers over here not having to stretch so much this distance Fn and Function keys, just to control volume and play/stop button. Can the function keys also be used for rewind, fast forward, screen brightness, keyboard brightness and next or previous song?, which would be right word usage to insert in the autohotkey script?

@DawnSaviours

This comment has been minimized.

Copy link

commented Jan 17, 2018

Cool, just found next media track or previous to add to the script:

; F2 key by default, Fn+F2 is now prev
MEDIA_PREV::F2
F2::MEDIA_PREV

; F3 key by default, Fn+F3 is now next
MEDIA_NEXT::F3
F3::MEDIA_NEXT

now only to remap F4 and F5 to screen brightness and F10 and F11 to rewind and fast forward,
who can help me with the right script words?

@Adrianrff

This comment has been minimized.

Copy link

commented Feb 27, 2018

This is awesome, I have a question though, what do the+#F21::, ^#BS::, etc mean after each assignment? Also, when testing a keyboard tester, pressing keys from F5 through F12 also show the ctrl (both), shift, and Lwin keys being pressed. However, using the fn button and an F key shows only the F key being pressed. Is the script not working for me? Thanks

@g048406

This comment has been minimized.

Copy link

commented Jul 26, 2018

@DawnSaviors: Just add this to the script (remember to delete lines 25-37 as this will replace the F4, F5 and F6 keys). PS: are you sure you want F4 to adjust the brightness? the F4 in the above script increases the volume):

F4:: AdjustBrightness(-1) ; decrease gamma value by 1 (-1)
F6:: DisplaySetBrightness(128) ; set gamma to standard value (128)
F5:: AdjustBrightness(+1) ; increase gamma value by 1 (+1)

; ===============================================================================================================================

AdjustBrightness(V = 0)
{
SB := (SB := DisplayGetBrightness() + V) > 255 ? 255 : SB < 0 ? 0 : SB
DisplaySetBrightness(SB)
}

DisplaySetBrightness(SB := 128)
{
loop % VarSetCapacity(GB, 1536) / 6
NumPut((N := (SB + 128) * (A_Index - 1)) > 65535 ? 65535 : N, GB, 2 * (A_Index - 1), "UShort")
DllCall("RtlMoveMemory", "Ptr", &GB + 512, "Ptr", &GB, "Ptr", 512)
DllCall("RtlMoveMemory", "Ptr", &GB + 1024, "Ptr", &GB, "Ptr", 512)
return DllCall("gdi32.dll\SetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0), "Ptr", &GB), DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
}

DisplayGetBrightness(ByRef GB := "")
{
VarSetCapacity(GB, 1536, 0)
DllCall("gdi32.dll\GetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0), "Ptr", &GB)
return NumGet(GB, 2, "UShort") - 128, DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
}

@JesMJM

This comment has been minimized.

Copy link

commented Nov 27, 2018

Is there a workaround like this but for linux/X11 ?

xmodmap can only remap from F1 to F4...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.