XMBC Simulated Keys via external hardware (arduino) device

x64 Replacement/Alternative to Microsoft's IntelliMouse application.
Forum rules
Please read the forum rules before posting for the first time.
The more information you can provide, the quicker and more accurately someone can help.
NOTE: To reduce spam, new users can not post links, files or images until they have at least 4 posts.
Post Reply
User avatar
phil
Site Admin
Posts: 7875
Joined: Sun Apr 06, 2003 11:12 pm

XMBC Simulated Keys via external hardware (arduino) device

Post by phil »

So, after a few discussions with people on the discord channel, I have been playing with using an Arduino to send simulated keystrokes instead of the MS SendInput APIs.

The Arduino is a tiny, cheap USB device that runs custom firmware. It is able to act as a USB HID device, and thus its just like a physical keyboard, but programmable. Ive written a simple firmware that XMBC can communicates with, and send keys that way. This means that the keys come from what appears to Windows as a standard, physical keyboard, which in turn means that the keys should work in any application, even if they don't accept simulated input (SendInput).

Curious to see if anyone is interested in testing it? If you are you will needs an Arduino based Pro Micro (may work with clones that use the ATmega32U4 CPU and support HID and serial communication at the same time - maybe all, I don't know) And it may need some further tweaks/config in XMBC for devices other than the Pro Micro (that I got amazon UK for about £12).

It's obviously a bit advanced, and still in its early stages, but it seems to be working for me. Its a bit slower than using SendInput, because each key down and up is sent to the device over its virtual serial COM port and waits until the device acknowledges it, but it can repeat keys at about 50-60ms. This can probably be improved but will require a lot more coding on the Arduino - and Im only just learning that :lol:.
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 11 x64 24H2, AMD Ryzen 9950x3D, MSI x870E Tomahawk, 64GB DDR%,
nVidia RTX 2070s (still lol)
User avatar
WIHedgehog
New User
Posts: 4
Joined: Wed Jan 22, 2025 6:27 pm

Re: XMBC Simulated Keys via external hardware (arduino) device

Post by WIHedgehog »

Would using an arduino bypass the hook limit of 5 buttons??? :shock:

--
P.S. I love XMouse, in the years I've been using it there's never been a glitch with it, it's solid. THANK YOU Phil!
User avatar
phil
Site Admin
Posts: 7875
Joined: Sun Apr 06, 2003 11:12 pm

Re: XMBC Simulated Keys via external hardware (arduino) device

Post by phil »

It depends what you mean.

If you mean using an arduino to send simulated keys etc. but still have XMBC translate the mouse buttons and communicate with the arduino to send keystrokes, then no not really, because the hook is the reception of the mouse messages (XMBC seeing what the mouse is sending through Windows), not the transmission of the mouse messages which the arduino could do...

But if you meant to put the Arduino in between the physical mouse and the PC (as in some sort of pre-PC filter) then maybe - you will have full HID access (assuming of course the mouse sends standard HID messages for these buttons), you can change it and or do what you want before the PC hardware, let alone Windows sees anything. But then XMBC is out of the loop completely, you would have to do the mappings etc in the arduino before it gets to the PC, or you would have to communicate from the Arduino to XMBC by some other means that the extra buttons have been pressed (then XMBC would need massive changes to the GUI and inner workings to accommodate that, and you would need a custom arduino project to receive the mouse HID commands, filter out the extra buttons (and send somehow to the PC & XMBC) and pass all other HID messages through to the PC over USB HID... A bit of a nightmare, but not impossible - not something I would be particularly interested in doing particularly given the effort involved (and custom hardware requirements making it a non-starter for the majority of users!).

It may also be possible without an arduino, using raw input, but just for the extra buttons that the windows hooks does not support. I looked into that many years ago but didn't really get very far, but I cant rule it out as a possibility, I can only rule it out as something I don't have time to look into myself these days!

There are also dedicated hardware options to so this already I believe - no XMBC required, but far less "user friendly"
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 11 x64 24H2, AMD Ryzen 9950x3D, MSI x870E Tomahawk, 64GB DDR%,
nVidia RTX 2070s (still lol)
User avatar
WIHedgehog
New User
Posts: 4
Joined: Wed Jan 22, 2025 6:27 pm

Re: XMBC Simulated Keys via external hardware (arduino) device

Post by WIHedgehog »

Disclaimer: I'm no expert. I can proficiently code, including Assembly without a macro assembler and hand-rolling Machine Code (assembers weren't always a thing), but haven't yet picked up an arduino. I believe that's mainly coded in C or C++, both of which I also have some experience with. I have not delved into USB signals so that's an unknown for me.

I was thinking to remap Naga V2 mouse output to keys like F13-F24, with XMouse monitoring the input from an arduino functioning as a HID, not necessarily a USB_mouse. At that point Universal Control Remapper might be a better fit, I don't know. I think that constantly reprogramming an arduino for the final output of keymaps would be tedious at best, something like XMouse is far more handy for managing translation and macros.

Like with you, time is also at a premium, but it's something to at least think about.
User avatar
phil
Site Admin
Posts: 7875
Joined: Sun Apr 06, 2003 11:12 pm

Re: XMBC Simulated Keys via external hardware (arduino) device

Post by phil »

I get it... The problem with that is how do you get that HID data from the arduino into XMB in the first place.
You would probably have to use something like raw/direct input, or write a device driver (that's not going to happen) or I guess take it via a keyboard hook (for keys such as F13-24) That maybe possible...

But if using direct/raw input to read the HID data, maybe it would be easier to use that to read the mouse HID data directly (if only I could find the time to have another look into that, it might be possible with things I have learnt since). Previously the problem I had with raw/direct input is that you can not discard it, so it is useless for remapping the standard 5 buttons that DO work through the mouse hooks, as they could not be blocked that way. But for buttons that do NOT work through the hook, it may be a viable solution.

The other problem with the arduino, is how do you make it generic, to work with multiple mice from different manufacturers which do the HID differently (assuming it is HID in the first place). In my experience different mouse manufacturers do it differently. I can't remember which, but at least one Logitech mouse I have had expose more than one HID device, for example (a classic HID mouse as well as two (I think) other HID devices (keyboards I think). Doing anything in hardware that is generic is going to potentially be a mamough task too (and your still needing the user to buy/build the hardware!)

But its certainly good to have such discussions. It triggers new thoughts and ideas if nothing else. And I'm a little surprised that no one found this topic sooner - whose sole purpose was to get a discussion going, if not specifically in this direction :)

I have played briefly with arduino twice, first to make a key injector that XMBC can use instead of "sendInput" so it appears the keys are sent from a dedicated hardware keyboard - (it kind'a works but its slow with the most basic hardware I chose, very rough and certainly not production ready!).
And, secondly most recently (last weekend) but not at all for XMBC purposes, I started playing with a new dev board which I aim to use to control my boiler (central heating) which for the last 18 years has been controlled by a C# program running on my server, and when I last replaced my server, I vowed to change it up because it was a nightmare bringing across the old hardware and IO devices into a modern virtual environment! This was all created long before the crazy of cloud based heating control that has been all the rage for the last few years (and its all local thank you very much!).

It is C/C++ based with wrappers to make it a little easier (or in my case, well versed in C/C++, make it a little more to learn lol). It also abstracts stuff quite well - I've not dealt with USB per say, but I have used it as a HID device to send keys, and a serial device to communicate with all over the one USB connection.

My assembler is pretty limited to 6502 - didn't get in to it deeply past that - moved on to Pascal briefly and then C/C++/C# which has served me well!

Its good and often fun to keep learning new (and in some cases old) things,, but also its time consuming and that's a struggle lol.
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 11 x64 24H2, AMD Ryzen 9950x3D, MSI x870E Tomahawk, 64GB DDR%,
nVidia RTX 2070s (still lol)
User avatar
WIHedgehog
New User
Posts: 4
Joined: Wed Jan 22, 2025 6:27 pm

Re: XMBC Simulated Keys via external hardware (arduino) device

Post by WIHedgehog »

As a note, every article I read when searching for what software to replace Razer SYNAPSE with listed XMouse, and listed it first at that. Granted most mice don't have 20 functions, but it's pretty impressive every list had XMouse, moreso that it's listed first.
Post Reply