Hierarchy or override Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Hierarchy or override

Post by Coiler » 30 Nov 2020, 10:37

I'm trying to create a multi-program hotkey mapping for the Tartarus Pro to work with a graphics tablet (Cintiq Pro 24). The basic setup is that the D-Pad and other thumb buttons will work as modifiers, which changes the function of all of the keys. That will result in 7 sets of hot-keys (4 DPAD directions, 2 buttons, and base keys).

All of the Tartarus Pro keys and modifiers are being read as joystick buttons to avoid conflicts with existing keys (I tried F13-F24, but there seems to be an issue with the Tartarus repeating keys when they are held down). I'm currently activating variable states when one of the 6 modifiers are pressed/released. So for example, when the DPAD UP is down, I set a variable MapOps=1, then set it back to MapOps=0 when it is released (the variables are actually bitflag bits, but I'm trying to keep this simple).

For the commands, I use #HotIf to assign remaps (such as Joy14::^c for copy) to each modifier situation. On top of the modifier buttons, there are also remaps for each specific program. I'm using #HotIf to diverge for programs as well (eg, #HotIf WinActive("ahk_exe Photoshop.exe")).

Currently, I am checking global remaps first, then app-specific remaps. Then inside each of those checks, I'm checking for the modifiers. But what I'd like to do is to have any keys not specifically assigned by the focused app to fall back onto the global version of those keys. Is there a clean and simple way to pull this off? I'm going to have a ton of remapped buttons in this, so I'm hoping to keep them as simple one-line remaps. I've considered creating multi-line hotkeys that check for each program in each key's hotkey, but that would become very difficult to manage quickly. I currently only deal with a handful of apps, and even now the code would be hard to manage without having each app's remaps all clustered together.

I have a lot of experience programming, but have little exposure to AHK. I've looked into the Hotkey system (Hotkey KeyName [, Callback, Options]), but I don't understand it well enough to know if it could help in this scenario. It mentions something about overrides in the docs, which sounds promising. But if I understand how it works correctly, I would have to create labels for every single hotkey, which would get out of hand quickly.

Here is an exported image of one of the Tartarus Pro remaps for clarity. This one would be active while holding RIGHT on the DPAD while Photoshop is focused.
Tartarus.png
Tartarus.png (1.06 MiB) Viewed 998 times
I appreciate any advice! I will be releasing this script and remap images (to print out) to the public for other Tartarus users if I ever get it completed.

User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Re: Hierarchy or override

Post by Coiler » 30 Nov 2020, 14:28

One very simple way to make this work would be to "overwrite" hot keys. Does anyone know if that is possible? If I define the global remaps first, I can then allow app-specific hotkeys to overwrite the keys that each program wants to change, and leave alone the keys they want to inherit. However, I think AHK will complain that these hotkeys already exist when the app (section) overwrites them. Does anyone know if its possible to ignore that condition and simply overwrite the hotkey? Maybe some type of preprocessor directive or a different mechanism for setting them up altogether?

CptRootBeard
Posts: 26
Joined: 16 Nov 2020, 14:47
Contact:

Re: Hierarchy or override  Topic is solved

Post by CptRootBeard » 04 Dec 2020, 13:15

Here's how I would go about this, personally:

Define all of your send commands in an external file/table similar to this:

Code: Select all

WinTitle, Hotkey, ModState, Send
Notepad, Joy14, 6, ^C
Notepad, Joy14, 4, ^P
Default, Joy14, 0, {Esc}
On startup, load this file into memory and create a lookup function that takes WinTitle, Hotkey, and ModState as inputs and returns the value in the Send column.
Make sure to define a default (non-app specific) set of commands in this file as well.

If the wintitle + hotkey + modstate combo isn't defined in the lookup table, it should return the default Send value for that hotkey.
If that hotkey has no default Send value, it should return an empty string.

Register the same function to all of your tartarus hot keys. That function should look something like this:

Code: Select all

runTartarusMacro(thisHotKey){
	;;Gets the title of the active window
	activeTitle := WinGetTitle("A")
	
	;;I'm assuming you have some function to check the overall state of the modkeys
	modState := getCurrentModState()
	
	;;Again, leaving the lookup and table structure up to you
	output := lookupOutput(activeTitle, thisHotKey, modState)
	
	;;I put the 'if(output)' here so we don't fire off an empty send. You're probably fine without it.
	if(output){
		Send(output)
	}
	
	return
}
There's a fair amount of work, but if you avoid all the #HotIf and directive mess up front, changing your numerous hotkeys and scenarios later on will be easier.
The possible downside to this method is a delay if your lookup function is slow, but there are plenty of ways around that as well.

Post Reply

Return to “Ask for Help (v2)”