Function lock for the Microsoft Wedge keyboard

I’ve just purchased a Microsoft Wedge keyboard for my Dell Venue 8 Pro. It’s a really nice keyboard but it has one big flaw for my use, the F keys are on a function shift (Fn) which means when programming I have to hit Fn-F2 to get F2 and not volume mute.

Fortunately it’s a fairly easy fix thanks to a great bit of software called AutoHotkey. This software lets you remap keyboard keys to others, run macros, build basic UIs, hotstrings and much more, it’s rather nice.

In this case I built a script that has 3 modes, Media keys on, F keys on, programmer mode which just does F1-F8 and leave F9-F12 requiring Fn pressing. I did that last mode as Print Screen, Home, End and Page Up are on F9-F12 and I use Home/End/PgUp way more than F10 or F11 which I only use when debugging.

I can switch between the modes with Win-; as the hotkey I’ve set up. The last thing I did was drop this into MyDocuments as wedgekeyboard.ahk, added a #include %A_ScriptDir%\wedgekeyboard.ahk to the autohotkey.ahk in there and set AutoHotkey to run on login by dropping its shortcut into the startup folder for my user in explorer.

It’s not the prettiest script but here it is.

SetAllOff()

; Wedge keyboard remaps
Media_Play_Pause::F1
Volume_Mute::F2
Volume_Down::F3
Volume_Up::F4
<+#F21::F5
<!<#F21::F6
<^<#F21::F7
<#F21::F8
PrintScreen::F9
Home::F10
End::F11
PgUp::F12
F1::Media_Play_Pause
F2::Volume_Mute
F3::Volume_Down
F4::Volume_Up
F5::<+#F21
F6::<!<#F21
F7::<^<#F21
F8::<#F21
F9::PrintScreen
F10::Home
F11::End
F12::PgUp
#;::NextStatus()

NextStatus()
{
  static Remap = 0 ; 0 - off, 1 - All F keys, 2 - F1-F8 only
  Remap++

  if Remap > 2
  {
    Remap := 0
  }

  if Remap = 0
  {
    SetAllOff()
  }

  if Remap = 1
  {
    SetAllOn()
  }
  
  if Remap = 2
  {
    SetProgramming()
  }
}


SetAllOff()
{
  TrayTip, Media keys on, Wedge keyboard, 1
  Hotkey, *Media_Play_Pause, off
  Hotkey, *Volume_Mute, off
  Hotkey, *Volume_Down, off
  Hotkey, *Volume_Up, off
  Hotkey, *<+#F21, off
  Hotkey, *<!<#F21, off
  Hotkey, *<^<#F21, off
  Hotkey, *<#F21, off
  Hotkey, *PrintScreen, off
  Hotkey, *Home, off
  Hotkey, *End, off
  Hotkey, *PgUp, off
  Hotkey, *F1, off
  Hotkey, *F2, off
  Hotkey, *F3, off
  Hotkey, *F4, off
  Hotkey, *F5, off
  Hotkey, *F6, off
  Hotkey, *F7, off
  Hotkey, *F8, off
  Hotkey, *F9, off
  Hotkey, *F10, off
  Hotkey, *F11, off
  Hotkey, *F12, off
  Hotkey, *Media_Play_Pause up, off
  Hotkey, *Volume_Mute up, off
  Hotkey, *Volume_Down up, off
  Hotkey, *Volume_Up up, off
  Hotkey, *<+#F21 up, off
  Hotkey, *<!<#F21 up, off
  Hotkey, *<^<#F21 up, off
  Hotkey, *<#F21 up, off
  Hotkey, *PrintScreen up, off
  Hotkey, *Home up, off
  Hotkey, *End up, off
  Hotkey, *PgUp up, off
  Hotkey, *F1 up, off
  Hotkey, *F2 up, off
  Hotkey, *F3 up, off
  Hotkey, *F4 up, off
  Hotkey, *F5 up, off
  Hotkey, *F6 up, off
  Hotkey, *F7 up, off
  Hotkey, *F8 up, off
  Hotkey, *F9 up, off
  Hotkey, *F10 up, off
  Hotkey, *F11 up, off
  Hotkey, *F12 up, off
}

SetAllOn()
{
  TrayTip, Function keys on, Wedge keyboard, 1
  Hotkey, *Media_Play_Pause, on
  Hotkey, *Volume_Mute, on
  Hotkey, *Volume_Down, on
  Hotkey, *Volume_Up, on
  Hotkey, *<+#F21, on
  Hotkey, *<!<#F21, on
  Hotkey, *<^<#F21, on
  Hotkey, *<#F21, on
  Hotkey, *PrintScreen, on
  Hotkey, *Home, on
  Hotkey, *End, on
  Hotkey, *PgUp, on
  Hotkey, *F1, on
  Hotkey, *F2, on
  Hotkey, *F3, on
  Hotkey, *F4, on
  Hotkey, *F5, on
  Hotkey, *F6, on
  Hotkey, *F7, on
  Hotkey, *F8, on
  Hotkey, *F9, on
  Hotkey, *F10, on
  Hotkey, *F11, on
  Hotkey, *F12, on
  Hotkey, *Media_Play_Pause up, on
  Hotkey, *Volume_Mute up, on
  Hotkey, *Volume_Down up, on
  Hotkey, *Volume_Up up, on
  Hotkey, *<+#F21 up, on
  Hotkey, *<!<#F21 up, on
  Hotkey, *<^<#F21 up, on
  Hotkey, *<#F21 up, on
  Hotkey, *PrintScreen up, on
  Hotkey, *Home up, on
  Hotkey, *End up, on
  Hotkey, *PgUp up, on
  Hotkey, *F1 up, on
  Hotkey, *F2 up, on
  Hotkey, *F3 up, on
  Hotkey, *F4 up, on
  Hotkey, *F5 up, on
  Hotkey, *F6 up, on
  Hotkey, *F7 up, on
  Hotkey, *F8 up, on
  Hotkey, *F9 up, on
  Hotkey, *F10 up, on
  Hotkey, *F11 up, on
  Hotkey, *F12 up, on
}

SetProgramming()
{
  TrayTip, Programmer mode on, Wedge keyboard, 1
  Hotkey, *Media_Play_Pause, on
  Hotkey, *Volume_Mute, on
  Hotkey, *Volume_Down, on
  Hotkey, *Volume_Up, on
  Hotkey, *<+#F21, on
  Hotkey, *<!<#F21, on
  Hotkey, *<^<#F21, on
  Hotkey, *<#F21, on
  Hotkey, *PrintScreen, off
  Hotkey, *Home, off
  Hotkey, *End, off
  Hotkey, *PgUp, off
  Hotkey, *F1, on
  Hotkey, *F2, on
  Hotkey, *F3, on
  Hotkey, *F4, on
  Hotkey, *F5, on
  Hotkey, *F6, on
  Hotkey, *F7, on
  Hotkey, *F8, on
  Hotkey, *F9, off
  Hotkey, *F10, off
  Hotkey, *F11, off
  Hotkey, *F12, off
  Hotkey, *Media_Play_Pause up, on
  Hotkey, *Volume_Mute up, on
  Hotkey, *Volume_Down up, on
  Hotkey, *Volume_Up up, on
  Hotkey, *<+#F21 up, on
  Hotkey, *<!<#F21 up, on
  Hotkey, *<^<#F21 up, on
  Hotkey, *<#F21 up, on
  Hotkey, *PrintScreen up, off
  Hotkey, *Home up, off
  Hotkey, *End up, off
  Hotkey, *PgUp up, off
  Hotkey, *F1 up, on
  Hotkey, *F2 up, on
  Hotkey, *F3 up, on
  Hotkey, *F4 up, on
  Hotkey, *F5 up, on
  Hotkey, *F6 up, on
  Hotkey, *F7 up, on
  Hotkey, *F8 up, on
  Hotkey, *F9 up, off
  Hotkey, *F10 up, off
  Hotkey, *F11 up, off
  Hotkey, *F12 up, off
}