Page 1 of 1

[Tutorial] Individual hotkeys with multiple keyboards

Posted: 30 Jan 2011, 02:01
by sixty
The Idea

This is something I had been wanting to do for a very long time! I love to have some extra keypads around my desk to accompany my main keyboard. I usually use them for non standard tasks, such as media keys to control my music or shortcuts in Photoshop.

For a task like this most people would use a tool like autohotkey to program macro scripts like these - and that is fine until... what happens if you have more than one keypad or if your actual keyboard has a keypad too? What if you just want a lot of macro keys? Sadly Autohotkey can not tell the difference between the same keys on multiple keyboards.

The Problem

Imagine the following situation:
Image

You have a numpad like this and you want to remap its "Tab" key to do something else - for example to mute your audio. You go ahead and write your Autohotkey script and then realize that the script will also trigger when you hit "Tab" on your main keyboard. Duh! No good. Our plan was not to give up keys, but to gain a few extra ones!

The problem is that autohotkey (and all other macro programs I tried) are unable to tell the difference between several connected input devices. This means every key you assign a macro too will also trigger on all of your connected keyboards.

The Solution

Recently I stumbled upon a little tool called HID macros. Originally written to be used with Flight Simulators, it is actually able to tell apart keystrokes from multiple connected keyboards!
HID Macros Website wrote:This small utility is written mainly for Flight Simluator (with extra feature for FSX Deluxe version), but can be also usefull if you want to activate keyboard macros from special keyboard(s). With latest version 1.5 mouse & game devices support was added (see below).

Key features
manage multiple keyboards/mouses connected to one PC
different key on different keyboard has assigned it's own command
mouse buttons on different mouses can be also used as macro trigeer - including mouse wheel
when a key activates macro, it's own beahvior (e.g. sending letter code to windows) is deactivated
macro can send another keyboard keys, launch application or send command to FSX via SimConnect
when no macro is assigned, keyboard/mouse works as usual
The tool is still pretty unknown and due to its original intention to be used with flight simulators - not very feature rich. The latest beta version allows for some very basic VBScript scripting, but still did not meet my needs. One of the few things that HID Macros can do out of the box is to launch another application. This gave me an idea.

Outsourcing work is always good!

So, HID Macros lacks a lot of features, but lets us launch other applications. Good enough! NirCmd is another little (60kb) standalone tool that kinda acts like a "swiss army knife" for common computing tasks. It gives you access to a ton of functions and commands by simply passing them to the command line parameter. There are dozens of things you can do with this. Just take a look at the massive list of features and examples. NirCmd has no UI and never spawns any visible window. The process ends as soon as the command was executed, invisible and silent.

The idea is to simply use HID Macros to detect a keypress and have it launch NirCmd with the desired parameters. Check out this little video to give you an idea and conclusion:
So there you have it, full freedom for your extra keypads or even full keyboards!

Posted: 30 Jan 2011, 17:44
by webwit
I've been looking for this for a while. I have two locations in the house were I access one computer, one location I use the DataHand, the other it varies, but usually something mapped to HHKB layout. But I need to manually toggle the remapping software, because it can't see different keyboards.

Posted: 30 Jan 2011, 17:57
by sixty
webwit wrote:I've been looking for this for a while. I have two locations in the house were I access one computer, one location I use the DataHand, the other it varies, but usually something mapped to HHKB layout. But I need to manually toggle the remapping software, because it can't see different keyboards.
Yeah this will work. Yesterday I found out you can also rename keyboards in the properties, so you do not even have to sort them through the ID. I think the next step would be for someone to write a wrapper for AHK that lets you run actual AHK macros depending on the passed on command line arguments or something. Anyway for now I am pretty happy with my solution.

Posted: 17 Mar 2011, 18:43
by alaricljs
A method for triggering AHK macros via a command-line AHK executable.

The basic idea is that you create a hidden GUI in your always running macro set and use the tiny exe to write info to the GUI and push the button.


Trigger script:

Code: Select all

DetectHiddenText On
DetectHiddenWindows On

SendThis = %1%
ControlSetText Edit1, %SendThis%,, UniqueIdentifier498
ControlClick, PressIt498,, UniqueIdentifier498
Return
Dead easy. You compile it and make sure that in the macro script you create the GUI with the correct button name and text entry name: PressIt498 and UniqueIdentifier498

Macro script:

Code: Select all

Gui Add, Button, gTriggerLabel, PressIt498
Gui Add, Edit, vTriggerMsg
Gui Add, Text,, UniqueIdentifier498
Gui Submit
return

TriggerLabel:
Gui Submit
if TriggerMsg = KickA
{
  Goto KickA
}
return

KickA:
; your macro here
return

Then you run the trigger with the right parameter (KickA in the example) and you're off. There's no error checking in this and if your macro script isn't running the trigger doesn't do anything about it.

Posted: 17 Mar 2011, 18:47
by sixty
Nice work around! I'll try it out on my daily macros tomorrow.

Posted: 18 Mar 2011, 22:14
by CephalicCarnage
Gonna have to bookmark this tutorial, as I'm currently in the market for a TK numeric pad. Looks like your work will really come in hand. Thanks!

Posted: 20 Mar 2011, 21:36
by amleth
AutoHotkey is a very nice one.
It has its own limit though.

Unfortunately I am not an programmer at all.
I just know how to use it.
Early this year, I tried language C.
It is horrible for me. Difficult.

Anyway.

AutoHotkey can control TWO 104 keyboards individually at the same time.

That means. You could have EXTRA 104 keys.
Actually. You can not control additional PrintScreen/Pause keys. Except these two, you have 102 keys.
In total, 206 keys are under your full control. I think that is just enough.


Please read this short post.
http://www.autohotkey.com/forum/topic10416.html

As I told you already. I, even do not know C, tried and succeeded that f**king MS special program for top level developer (language? or whatever) DDK (aka WDK or something). Of course I just modified very tiny part like keyboard switch modification ^^.

Basically, If you press "a" key of your board, it sends scan code "0x1E".
This fact does not change how many boards you connect into your computer.
This "a" key is just same as that "a" key.

But, After you install KBD filter driver. Story is different.
You can distinguish this boad "a" from that board "a".
One sends regular/original/unchanged/unmodified "0x1E", but the other sends modified "0x11E".
Do you reconize this strange scan code 0x11E ?
Yes, it is a emty one. Nobody knows it. From now on, it is all yours.

Mine is basically just adds 100 for every scan codes.
That is kind of easy to remember and easy to use it.

for example, first 4 keys in "that" board are:

Sc11E:: ; a key
Sc11F:: ; s key
Sc120:: ; d key
Sc121:: ; f key

interesting is not it ?

I told all of those thing I know in the post (my nick name is hamlet there).
And still I have all files for it.

If you need it just tell me. I could tell you all modifications I did and all codes/files.
On one condition. If you are one of those arrogant gurus, forget it. I do not want to talk to you anymore.

Bye..

Posted: 20 Jun 2013, 15:52
by The Demongolator
The Demongolator hath collected.