Can you remap keys of a specific keyboard?
Asked Answered
Y

2

14

I've got two keyboards attached to my computer. A normal full-size keyboard and a numeric keypad. I want to "remap" the keys on the numeric keypad, but leave the full keyboard alone. So, when the user presses "5" on the keypad it would get remapped to the "Media Play" key, but if the same "5" was pressed on the keypad of the full keyboard, I'd get a "5". In essence, I want to turn that seperate numeric keypad into a media control device.

Unfortunately I'm not sure how to make this work. There is a "Raw Input" feature of Windows which allows to distinguish between keyboards, but that only allows to read the keys - not remap them. There are keyboard hooks (low level and high level) which can remap the keystrokes, but they don't distinguish between keyboards.

Can I make a combination of the two methods work? For that I'd have to be sure that the raw input message is processed before the keyboard hook kicks in. Is that so?

Also, I've read that Windows for some reason does not allow to use Raw Input and Keyboard Hooks in the same process. I could work around that by making 2 different processes, but that becomes more fragile because of communication latency (keyboard hooks have very limited time in which they must complete their work).

Is this doable at all?

Yim answered 6/12, 2012 at 11:26 Comment(0)
Y
8

In the end it turned out I needed a custom keyboard driver to accomplish this. Fortunately I found one ready for taking - Interception. The app is ready and works perfectly. :)

Yim answered 5/4, 2013 at 11:22 Comment(24)
Is this app public? It sounds very useful.Thermoscope
@Thermoscope - no, I haven't published it, but it needs a lot of polish to be useful to others. I've hardcoded both my keypad hardware ID, and the key mapping. In its current state, if you wanted to adapt it to your own needs, you might as well just write one from scratch.Yim
@Thermoscope - Still, if you want it, here you go: valts.21.lv/Mediaception.zip. Just remember that you need to install the driver too, which you can download from the Interception website above.Yim
I found another project that uses the Interception driver, and discovers the info it needs to write an .ini-style configuration, it's very handy, I was up and running in about half an hour. The interceptor multi-keyboard remapping binary and source code is on this Orbiter forum post, it requires registering with their forum to download.Thermoscope
I install the program, but I don't see where I can call it to remap my keyboard.Cymene
@AndiJay - which program? My Mediaception, the Interception driver, or the thing on the Orbiter forum?Yim
Running the install-interception.exe gives me usage: C:\path\to\Interception\command line installer\install-interception.exe [/install | /uninstall]. Any idea what those "instructions" mean ?Shamanism
Kids these days! 😄You need to use the command line and run install-interception.exe /install.Yim
I've spent days looking for a solution like that. Thank you so much.Sextet
@RodrigoBorba - Lately it's become unreliable on my Windows 10 machine. It often stops sending signals, and on occasion even locks down all keyboards entirely, so that not even a reboot helps. In that case you need to uninstall it (Windows on-screen keyboard still works), and reinstall.Yim
Unfortunately I've found it out already. I kept looking for a better ready solution but i could't find one. I'm starting to developer a definitive solution. Maybe open source. I'll share the repository as soon as I get something ready.Sextet
@RodrigoBorba - The way Inception does it is via a special driver. And drivers are tricky. Writing them is one thing, but if you want to get it installed without much trouble, you'll need to get Microsoft's signature on it, and I don't know the process or expenses for that.Yim
I have to study more about it, but I think it is possible to install a unsigned driver. As it would be a open source solution, it won't be very hard to check whether the code is malicious or not.Sextet
@RodrigoBorba - Sure, you can. After all - you need to be able to write them and test them, right? But there's hoops to jump through and it won't be end-user friendly.Yim
That is right. At less we would have some sort of solution...Sextet
@RodrigoBorba - If you make it, let me know! Driver development is a dark mystery to me. :)Yim
Let us continue this discussion in chat.Sextet
@RodrigoBorba is this chat still open? I'm looking for a solution to remap a single keyboardDemasculinize
Is there any way to adapt the keyboard itself so that keys can be remapped on the keyboard side and completely skip the windows software? I guess this will vary from keyboard to keyboard but just to raise a thought process...Demasculinize
I'm not trying to spam the comments, but just had a brainwave... if keyboard can't be remapped, maybe I can have an i/o device between keyboard and PC that simply changes the input to a different output... and it might be possible. I can set up a Pi as keyboard device, plug keyboard into pi, write code to turn one input into another. Got a Pi on order right now! randomnerdtutorials.com/raspberry-pi-zero-usb-keyboard-hid/….Demasculinize
@5Diraptor - When you start playing with hardware, anything's possible. However I don't think that you will be able to simply take a consumer-grade keyboard and remap it. The chips in there aren't meant to be reprogrammed. But you could use parts of it... either replace the chip with a different one that you can program, or keep the chip and make a custom keyboard. Both options however will be a lot of work.Yim
@5Diraptor - The other option you mentioned is using some hardware in the middle. That is... umm... definitely possible, but I wouldn't know even where to start. For one thing you would need the PI (or whatever) to act both as a USB host and a USB slave. And you'd have to do some low level USB mungling... or find a software that lets PI emulate a keyboard - maybe that would be easier. Still plenty of work.Yim
@5Diraptor - This is the reason why I wanted a software solution on the PC - because I judge that to be the easiest way. In principle there is already enough information coming in to do this - the question is just if the OS supports a way to do it. Maybe Linux has better facilities? I don't know.Yim
@5Diraptor I actually dropped this approach, but I still think it is doable. I just do not have time to invest on it anymore. The idea behind is to have a drive that overrides the default browser for a specific UID of an USB device. Having a device in the middle is also a valid solution, but demands hardwareSextet
D
4

I wanted to expand on the answer by Vilx as I've revisited this post several times, and I've only just managed to remap my second keyboard so the keys act uniquely. This is done using Interception and Intercept together, and it's the only working solution that I've managed to get working so far.

I'm also looking into using a raspberry pi to remap a second keyboard. Although early days, I think it it's achievable: Plug keyboard into Pi, plug Pi into PC and write script to turn input keycodes into customized output commands / keycodes. Will update when I have tested.

My working Intercept solution is completely based on a Github tutorial by TaranVH which details the process the best so far. I've copied his solution below with some amends of my own.

DOWNLOADING INTERCEPTION:

  1. Navigate to this page: https://github.com/oblitum/Interception
  2. Click on "download the latest release."
  3. Click on Interception.zip to download it.
  4. Unzip the file to a folder on your computer - I recommend using a folder location that won't ever move. I put my Interception folder into C:\Program Files\ and I'll be using this location in my examples.

INSTALLING INTERCEPTION:

  1. Open a terminal as administrator and type cd "C:\Program Files\Interception\command line installer"
  2. Hit Enter
  3. Now, type in the following line of text exactly as shown: install-interception.exe /install
  4. Hit Enter

Once the program installs sucessfully, you still must restart your computer in order to complete the installation.

(If you ever want to UNinstall interception, watch this): https://www.youtube.com/watch?v=Hn18vv--sFY

INSTALLING INTERCEPT - (This is different from intercepTION!)

  1. Download Kamaz's intercept.exe zip from one of these locations:

    1. http://octopup.org/img/code/interception/intercept.zip
    2. https://github.com/TaranVH/2nd-keyboard/blob/master/Intercept/intercept.exe
  2. Unzip it if it's a .zip file and locate intercept.exe

  3. To keep these files all in one place, I moved intercept.exe into C:\Program Files\Interception\

  4. Reboot your system.

SETTING UP INTERCEPT

  1. Plug in your second keyboard and ensure that it is working normally.
  2. Go to where you saved intercept.exe and double click to open.
  3. Intercept will open as a terminal, and from there you should have basic instructions to start remapping your keyboard.

  1. Type a to add a key.

  2. On the SECONDARY keyboard, press the Q key once. (this is the key that you are remapping)

  3. You will be prompted with Enter combo for this trigger, end with ESC.

  4. Carefully execute the following keystrokes (it doesn't matter which keyboard): Win + E (That is: hold down the windows key while pressing the letter E. I've found you need to do this quickly and accurately, if you hold down too long, extra keypresses are added)

  5. When I did it, this was shown in the terminal: [Left Windows]↓ [E]↓ [E]↑ [Left Windows]↑

  6. Press Esc and you will be prompted to label the script

  7. I labelled mine Q->WinE so I knew what it was doing.

  8. Press Enter to accept the label

  9. Press S to save the filter, or C to cancel if you made a mistake.

  10. Add more filters or close the terminal.

USING INTERCEPT

Now you've set up a custom key command, you need to apply the filter to use it.

  1. Open up intercept.exe
  2. Press Y to apply the filters, you will get confirmation that the filters have been activated.
  3. Now, when you press Q on your second keyboard, Intercept will change the command to Win+E which will open File Explorer.

Caveat:

Demasculinize answered 26/5, 2022 at 11:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.