How to program my keyboard's numeric keypad?

I use a WASD CODE 104-Key Mechanical Keyboard with my MacBook Pro. (The MacBook Pro is generally closed and connected to my LG monitor.)

I'd like to reprogram the numeric keypad on my WASD keyboard so that it basically has two modes, which I'd be able to easily toggle between using a keyboard shortcut or by pressing the numlock key.

In the first mode, the numeric keypad would function as normal. In the second mode, the numeric keypad would be reprogrammed, e.g. the "0" key would replicate the ⌘+W key combo, the "1" key would replicate the ⌘+C key combo, the "2" key would launch an application, etc.. (This reprogramming should only impact the number keys on the numeric keypad, not the keyboard's top row number keys.)

Is this possible to accomplish with Keyboard Maestro? I'd be grateful for any guidance.

KM does not provide support for low-level keyboard control.
For that, you might use Karabiner-Elements .

At least with the full-size Apple external keyboard, Keyboard Maestro does distinguish between keys on the number pad versus "the keyboard's top row number keys." Maybe the above-linked Karabiner Elements can help—the old version I use has number pad options, but I don't know how things could be set up so there are two modes.

If the goal is just to have the number pad behave like a number pad in a certain app (or apps), then custom behaviors could be configured with Keyboard Maestro. For example, only in Excel and TextEdit does the number pad act as expected, but elsewhere pressing number pad 4 is like pressing Command-C.

1 Like

Thank you, @NaOH. That's along the lines of what I'm looking to do.

Are there instructions anywhere on how to configure this custom behavior?

Is it possible to differentiate not only by app, but also (when using Chrome or another browser) by what website you're visiting?

[EDIT: Tidied things up a bit.]

I have an Apple Magic Keyboard with Numeric Keypad and KM does differentiate between the numpad keys and the others, so it is possible to remap them but it's not what I would call "pretty"!

Please note: I'm not saying this is a solution to your requirement but it might help you find the answer to your question.

So here goes...

First you need a macro to toggle the remapping. I've called it Numpad Mode Switch and it looks like this:

KM 1 2020-07-20_16-55-36

It basically sets a global variable to indicate whether the numpad keys are in remap mode or normal mode. I've set it to trigger when the Command-Enter keys are pressed. Here's the macro to download:

Numpad Mode Switch.kmmacros (4.9 KB)

Next comes the macro that actually does the remapping, and this is where it gets "not pretty". I've called the macro Numpad Remapping and here it is to download:

Numpad Remapping.kmmacros (25.8 KB)

(Both of these macros should be in you Global Macro Group, or equivalent.)

This macro is triggered by the numpad keys (I've included 0 to 9 and the decimal point as well). It works like this:

If the numpad is in normal mode, then the macro just repeats the key that's been pressed (the section of the macro in green).

If the numpad is in mapped mode (the section in teal), it replaces the pressed key with something else and executes it. In the macro itself, the mapping is performed by the actions coloured magenta; at present the macro just remaps the pressed key to a different one, but you can change these actions to any other actions (such as launching an app for example) as you wish - that's up to you.

I'm including an image of this macro at the end - just so others can see how it is constructed, but it is very long so I apologise in advance to posting something so unwieldy.

If you wanted to perform remapping depending on what app you are using, you could trigger the Numpad Mode Switch macro when that app comes to the front, but then you'd also have to reset the mode to normal once you leave that app. That's an exercise for you to work on!

I know you don't have an Apple keyboard, but you might be able to get some ideas from this post.

Good luck and let us know how you get on!

2 Likes

Thanks so much for taking the time to share this, @tiffle.

The work @tiffle has provided is much better than anything I would have demonstrated, so I'll defer to that macro.

2 Likes

@peternlewis has previously indicated that this may not be reliable, i.e., when a Macro does a Typed Keystroke of the same keystroke used to trigger it.

@tiffle has a good idea, but I'd suggest this:

  1. Create a Macro Group, maybe named "Keypad ALT Mode", which will contain all of your Macros to be used in the "alternate" mode.

    • Set this Group to be Activated/Deactivated When a HotKey is pressed, like this:
    • image
  2. Create one Macro for each keypad key you want to remap, with the trigger obviously being the keypad key.

  3. Whenever you want the keypad in "ALT mode", just press the hot key. Press again to toggle back to normal mode.

EDIT: I just tested this to confirm, and initially when the ALT Group is created with the Activation toggle, it will be INACTIVE until you press the Activation Hotkey the first time.

Will that work for you?

2 Likes

Thinking about it, that’s a bit of a gotcha if it’s correct. I hadn’t considered a macro typing a keystroke that is used to trigger it. How does your approach avoid that if you remap a numpad key to another numpad key or is it just something better left to Karabiner Elements?

Remapping keys is not something that should generally be done in Keyboard Maestro. A low level tool like Karabiner Elements is generally the correct solution.

Note that mapping keys is fine. So for example, if you want Command-L to what Command-J currently does, and currently Command-L does nothing, then it is fine to write a macro with hot key Command-L and action Type Command-J. that sort of mapping is fine and will not cause a problem.

The problems come when you want to do remapping - mapping between different keys you use. Eg swapping Command-L and Command-J. You can sometimes get away with this sort of thing with mapping Command-L to a menu selection and Command-J to another menu selection o something like that.

But general remapping of keys for different purposes is not something that will end well.

2 Likes

Thanks for explaining so clearly. The power of KM wielded wisely must be :obi-wan emoji here:

I've reprogrammed the numeric keypad via karabiner elements. Let me know if that code would be helpful.

You definately want Karabiner for this. Its easy and reliable if you want this low level functionality.

You map all those numeric keys to mouse buttons 10-30 in karabiner for this specific keyboard.

Now they will never interfer or behave like numeric keys.

Then you can map those mouse button numbers in keyboard maestro globally or for specific apps using the usb device key trigger.

Remap those triggers in keyboard maestro to numeric keys or any other combos for a specific app.

Or create a toggle that switches between 2 macro groups.

This will also work for remapping a full 2nd keyboard a - z. As there are 30 virtual mouse buttons in Karabiner you can use. So there is always 27 extra buttons to use if you use a 3 button mouse.

Karabiner and keyboard maestro are a wonderful pair together.

2 Likes

@JMichaelTX @NaOH @tiffle @peternlewis @Jonathan_Zuck @tpj2018 -

Thank you all for your ideas here and apologies for the slow response.

The solution that @JMichaelTX proposed doesn't seem to require Karabiner whereas @peternlewis, @Jonathan_Zuck, and @tpj2018 suggest going with Karabiner.

I'm not opposed to using Karabiner, but if you guys don't see any issues with the solution proposed by @JMichaelTX, it would probably be preferable to avoid relying on an additional app.

In case it's helpful, it seems like KM already identifies my keypad keys as independent from the number keys on "main" section of the keyboard. Here's an example...

1 Like

Thanks for sharing.
FYI, it is easier for you, and for us, if you will just drag/drop, or copy/paste your images directly into the Forum post.

Thanks.

Got it! I've edited my post.

2 Likes

So as I'm getting more into automating routine tasks. I stumbled upon the proverbial, hyper key. It looks like it's been added to the application, BetterTouchTool, recently.

Question and/or confirmation: Is it better for me to alter the keypads in BetterTouchTool now?

I had repurposed the ESC button to Toggle Full Screen (ie. Cmd + Ctrl + F) in Keyboard Maestro. Since I remapped the CAPS LOCK to Cmd + Alt + Ctrl + Shft (ie. hyper), I was going to remap all of the keypads in BetterTouchTool as @peternlewis advised. Keep it neat and tidy, yes?

BetterTouchTool adds: "Act as Hyper Key"