Skip to content

Making an extra mouse button translate to CTRL HOME CTRL END

Kirk Woll edited this page Sep 23, 2017 · 1 revision

I have a mouse that has two extra buttons. I like to use them to jump to the beginning and end of a document. Mapping these buttons to CTRL + HOME and CTRL + END respectively. To achieve this, add these lines to your script.

Keyboard.AddShortcut(new Shortcut(KeyCode.ExtraButton2), _ =>
{
    Keyboard.SendKeyDown(KeyCode.Control);
    Keyboard.SendKeyPress(KeyCode.Home);
    Keyboard.SendKeyUp(KeyCode.Control);
});
Keyboard.AddShortcut(new Shortcut(KeyCode.ExtraButton1), _ =>
{
    Keyboard.SendKeyDown(KeyCode.Control);
    Keyboard.SendKeyPress(KeyCode.End);
    Keyboard.SendKeyUp(KeyCode.Control);
});

SendKeyDown / SendKeyUp is equivalent to SendKeyPress, but if you need more granular timing between down and up, the former pair is useful. Here, we want to "press" the CTRL key, and then press either HOME or END, and then finish up by "releasing" the CTRL key.

Clone this wiki locally