A small daemon, switches macros with the foreground app.

Announcements, general discussion
Post Reply
cristiano_pruneri
Posts: 14
Joined: 19 Jul 2013, 12:43

A small daemon, switches macros with the foreground app.

Post by cristiano_pruneri » 29 Oct 2014, 17:57

I use HIDMacros to convert a compact keyboard in a big hot-keys machine, for drawing.

I keep said keyboard vertical, on the side of my drawing tablet... ( see here https://www.youtube.com/watch?v=9cOSlbgOUqA to get what I mean. )

For my purposes, it works quite well, as it frees me from reaching the keyboard with my drawing hand, as well as it gives way more keys than most drawing tablets with hot-keys on the side (usually, those are just 8).

However, I realized that HM , being designed mainly as a X-Plane help, misses a couple of desirable features.

One of them is the ability of switching macro, on the base of foreground window.

This is something that the drivers for the various Wacom Intuos[es] do, as it allows to work around the difference of interfaces of the various drawing programs (not all of them allows to re-define their short-cuts).

I wrote a small java program that kills HM, changes the hidmacros.xml file, and then restarts HM, when the foreground window change and it happens that the new window has associated a set of macros.

You can find it here:

https://www.dropbox.com/sh/ul13bv7xy86p ... 6CVMa?dl=0

it must be placed in the same directory of HIDMacros .exe.

When launched, he launches HIDMacros and creates a directory called repository (or something).

This will contain a "lock" file (to avoid launching more than one instance of the daemon), a list of ignored applications (explore.exe and others), an xml file containing the skeleton of the macro it uses to "mark" each file, and a directory called macros containing a copy of the current hidmacros.xml configuration file (called, instead, generic_application.stored.xml) .

All the saved files are simply text, so you can change them as you better saw fit (as long as you do not "break" them... aside from the xml, the others are just columns of application's names, no trailing spaces please).

When hidmacros saves his macros file, the daemon saves a copy of it in the repository, marking it with a "bogus" macro (actually, it's a"loopback" macro, that tells the daemon to show a credit message) and procedes, from then on, to replace the hidmacros file when you pass to that window again.

Said copy will be associated to the last windows in foreground (the one before the hidmacros UI itself, when you save using save configuration... Note: if the daemon needs to mark the macros set, it will kill and relaunch hidmacros so that the added/modified mark macro is visible).

It attaches an icon in the tray, through which he can be controlled.

On a double clicks, it shows the macro sets presently defined.

Right click, it shows a menu with stop, enable-desable-delete macros sets, enable/disable expansion mode options.

With the expansion mode disabled, "unknown" application are treated as instances of a "generic application", and thus a macro set named "generic application" is used.
As I said, it is just a copy of the hidmacros.xml file that was there when the daemon was first launched, but it can be modified as every other app.

When "expansion" is enabled, unknown applications are ignored till HIDmacros does not save his macros. Then, the recently saved set of macros is "hijacked" and used as that application, specific, set.

So, let's say I need to "port" the macros form photoshop to Manga studio.

All I have to do is open Photoshop, wait for the daemon to popping me that the switch of HM config has been done (unless the current is a file marked to be used with Photosop), then alt-tab to manga studio and then, tab to hidmacros and re-save the configuration. The daemon will see to it that that config will be saved as Manga studio something.
Also, as it will have to replace the config marker, so it will kill and relaunch hidmacros (sorry for this).

It is pretty crude, and probably can and should be tweaked-developed a lot (for example, could be added a "sudden-death, restart after a couple of minutes" feature, so that when you touch a dead accent key in your "main" keyboard, hidmacros is killed for a while, or a way to add arbitrary modifier keys) but, for the time being, this is as far as I can go with it.

If someone is proficient with java and wants to pick it up, the jar also contains the source code and the project files from Eclipse.

I know, it's an unholy mess... it is a couple of years that I do not program, so all the good habits were lost.

By the way, if there is some way to convince HIDMacros to reload the macros file while it run, without killing and relaunching the poor guy, it would be wondrous.

Regards,
Cris

Post Reply