Add modifier keys and other keyboard keys to 'Advanced Conditions' in 'Trigger Conditions'

Currently it seems that the 'Advanced Conditions' in 'Trigger Conditions' of a 'Keyboard Shortcut' has no way of including checks for various keyboard keys, modifiers, etc.

It would be really awesome to be able to add a condition to check if another key is already being held down, if a modifier is active, if caps lock is turned on, etc.

Eg. It would provide a simpler solution for this: Is it possible to make new layers using BTT - #3 by devalias

Or it would allow me to easily set a keyboard shortcut to not run if I'm holding down another key (I have Ctrl+Option+Left, Ctrl+Option+Up, and I want to add a keyboard sequence that triggers Ctrl+Option+Left+Up that does something different; but currently it seems I can't easily prevent the standard shortcuts I configured from running; except to tell them to not run if another shortcut has run within Xsec, or not run if a certain UUID has recently run, etc (which isn't user-friendly in the UI)

Keyboard shortcuts only trigger if the specified keys are pressed. Any additional modifier keys would lead to that shortcut not triggering. Or did I misunderstand something? How would your example be possible when the conditions would allow to check for keys/modifiers?

So I have:

  • Keyboard Shortcut
    • Ctrl+Option+Left that moves/resizes the window to the bottom left corner of the screen
    • Ctrl+Option+Up that moves/resizes the window to the top center of the screen

image

I wanted to create a new 'Keyboard Shortcut' as follows, but it wasn't possible to create a shortcut that has both the Left and Up arrow keys:

  • Ctrl+Option+Left+Up that moves/resizes the window to the top left corner of the screen

Since I couldn't do it directly with a 'Keyboard Shortcut', I figured that I could do it with a 'Keyboard Sequence' instead. So I recorded this sequence:

image

Firstly, it would have been ideal if I didn't have to record the Ctrl+Option as part of the key sequence, as I don't want to have to press them in the specified order; I just care that those modifiers are currently active. It would have been much better if I could have used the standard 'Trigger only while holding these keys' sort of functionality that is available to other trigger types:

image

But since that wasn't possible, I figured maybe I could check if Ctrl+Option were active from the advanced conditions; but it seems that we aren't able to use keyboard / modifier keys in the advanced conditions on triggers at all:

That's my first use case, but it's something I can work around in the meantime by just having the Ctrl+Option recorded in the sequence, and ensuring I press them in the perfectly correct order every time.

So now that I have the 2 keyboard shorcuts + the 1 key sequence set up, when I try and press the key sequence, all 3 of them activate:

  • First Ctrl+Option+Left
  • Then Ctrl+Option+Up
  • Finally Ctrl+Option+Left+Up

If I was able to use keyboard modifiers/etc in the 'advanced conditions' of the 'Keyboard Shortcuts'; then I would be able to do something like configuring Ctrl+Option+Top to not run when the Left key is being pressed, or similar.

Another use case for being able to use keyboard modifiers in advanced conditions would be something like this:

Ok, I have added currently pressed keys to the advanced condtions for the next version

It will show the key codes of all pressed keys.

For the layers thing I still think you could just setup normal keyboard shortcuts. E.g. cmd+shift+a => trigger arrow left, cmd+shift+d => trigger arrow right ....

1 Like

@devalias I admit that it's not completely clear to me why you would want to do it that way. :slightly_smiling_face: Is it because you're running out of modifiers? If so

With a combination of the "Advanced Conditions" and short/long press, you can configure something very handy ... with any key.

Short example with "f".

  • Press and release "f" quickly types "f". (Note that the letter is typed when you release the key).

  • Press and hold "f". Now a new "modifier" is created. Press additionally the key you want and the shortcut is executed.

Release "f" and everything is as before.

1 Like

@Andreas_Hegenberg Awesome! Thanks a lot for that! :slight_smile:

RE: Layers, I think his goal was to basically change how the keyboard works in general while capslock was enabled (I might be wrong, that was my assumption). So that when in 'capslock trigger mode', certain keys can be set to trigger a function on it's own. Eg. W (with no other keys pressed) would map to Up, etc. That's why I suggested (on the other thread) creating a new preset and enabling/disabling it when caps lock is toggled.


@Frank1 I definitely use a lot of key combos/modifiers, but it's less about 'running out' of them and more about mapping them to what feels logical for my brain. I have use cases where I want the window at the top of the screen, others left, others bottom right, others top right, etc; and while I could assign it to arbitrary other keys, what makes the most sense to my brain (and thus the easiest to remember without learning cryptic shortcuts) is to use the arrow keys.

That said.. that is a SUPER useful technique to keep in mind! Just because it isn't super clear to me at the moment, how would you go about setting up the 'hold F + something else' to trigger a shortcut using the advanced conditions? And is that before the new currently_pressed_keyboard_keys changes mentioned above, or since they're implemented?

The "f" example was based on my assumption that you had too few modifiers.

I'm happy to explain. But the disadvantage is that the letter "f" is then typed when you release it, which can lead to letter twists when writing fast. That's why I don't use it.

1 Like

Makes sense, and I likely wouldn't end up using a normal letter like that (more likely to use a number or similar that I use less in normal typing), but am definitely curious as to how you achieve the 'turn anything into a modifier key' approach, regardless of which key I end up choosing to do it.

You are smart :slightly_smiling_face: I do it the same way. I "sacrifice" the key "4", which I can reach blindly with my left index finger.

Ok, then things are easy because there is no short/long press needed. But "4" loses its function. If you need it you have to press fn 4.

Set up two shortcuts. (1) triggers on "down" and the (2) on "up". The screenshots are in German, but I hope you understand.

1. Press and hold "4".

  • Save current mouse position
  • The mouse moves to the menu bar (y = 0)

2. Release "4".

  • The mouse returns to the saved position

Now, let's say "4" + "j" should be "left arrow". (But it can be anything you want)

Set up two actions with the advanced conditions for "j".

1. "j" = "j" if the mouse is not over the menu bar (y not 0). Activate "Prevent recursive trigger"

2. "j" = left arrow if the mouse is over the menu bar (y = 0).

That's all. "4" now works like a modifier.

There are other ways to do this. For example, "4" you can toggle a Stream Deck Emulator Window (instead of moving your mouse to the menu bar and back). This has the advantage that you can see the shortcuts if you don't know them by heart.

Let me know if something is not clear. :slightly_smiling_face:

1 Like

Ah ok, so essentially the position of the mouse being over the menubar or not is the thing that acts as the 'modifier active' state; which you manipulate based on the key (4) being held down?

Clever way to approach it! I wouldn't have even thought to use the mouse pointer position like that!


While I haven't tried it, I was thinking that I could also just set it up so that a 'normal' press would continue to type the key as normal, but a 'long' press/hold would then make it the 'modifier' key. I think that way the only functionality I would lose from the key is being able to hold it down for repeated keys (eg. 444444444)

Screenshot 2023-01-24 at 7.04.22 am

Just tried it though, and it seems that even when the trigger is set up to have a minimum hold time, it still prevents the standard key from working in normal typed situations :cry:

I was thinking maybe I could just create a 2nd shortcut that triggers on a short press, as the link there suggests:

And playing around with it now.. that seems to work:

Created 2 triggers, one for the 'long press', one for the 'short press':
image

For the long press:

  • Prevent recursive triggers
  • Trigger on Key Down
  • Minimum time keys need to be pressed: 1sec

image

And then i'm just using a Hud Overlay for the test long-press action:

image

image

For the short press:

  • Prevent recursive triggers
  • Trigger on Key Up
  • Minimum hold time: 0sec
  • Maximum hold time: 0.99sec

image

For the short-press action, I'm basically just having it send through the same key as my trigger, so in this case, b:
image

So now, if I long-press b, then the hud overlay is shown:
Screenshot 2023-01-24 at 7.20.12 am

And yet I can still type b normally, and it functions as though there was no long-press key assigned to it; at least for the most part. There seems to be the slightest bit of lag, so when I can type really fast, it ends up putting the b 1-character out of order. eg. When I am typing 'be' I can press the keys so fast that it ends up being 'eb' due to the lag. Very occasionally it also seems that it might end up doubling the letter, so I end up with 'bb' typed. So for that reason I would probably still choose not to assign it to a key I use super often in typing. But for the most part, it seems to work pretty well!

Something else I only just discovered (or maybe re-discovered), is that if I have multiple actions assigned to the same shortcut, then BetterTouchTool will show a little menu and let me choose which one I want to trigger. So for this test I just duplicated the long-press action and gave it a different description:
image

And now when I long-press it, I get the menu to choose which one I want to trigger:
image


I was also thinking that maybe we could use the 'assign value to variable' action to store the 'modifier active' state (rather than your method of moving the mouse onto the menu bar/back), but it seems that we can't read that from the 'trigger conditions' 'advanced conditions' :frowning:

image

Edit: For this last use case, I just opened a new Feature Request:

Edit 2: So it seems that it's already possible to use custom variables in the advanced conditions!

Continuing on from my 'Edit2' discovery above.

We can use an action on the 'long-press' trigger to assign a value to a variable (eg. isBLongPressed):

image

And then read that variable in the 'advanced trigger conditions' of a different trigger:
image

image

We would also need to make sure to 'unset' our variable when the B key is released, so putting something like this in a 'key up' trigger:

image

I originally tried having 2 'short-press' shortcuts configured on 'key up', the first with the min/max hold time as shown in my previous message, and the second that had no max hold time; but having 2 shortcuts set up (even with the different hold times) resulted in the 'which one did you want to run' menu being shown.

I then tried just having the 'short-press' shortcut without min/max time on 'key up', which worked well, but resulted in an extra b being typed when using my long-press shortcut, which wasn't ideal.

I was thinking maybe I could be 'extra tricky' and configure a 3rd action so that I have:

  • Long-Press (key down, min hold 1 sec): set isBLongPressed = true
  • Short-Press 1 (key up, min hold 1 sec, no max hold): set isBLongPressed = false
  • Short-Press 2 (key up, no min hold, max hold 0.99sec): send B key and set isBLongPressed = false

Screenshot 2023-01-24 at 8.21.51 am

My theory with this was that it should prevent the extra B being sent through on a long press, since the only way that the B is being 'typed' is by 'Short-Press 2', so if it's configured not to run when the key has been held for the 'long press time', then it shouldn't trigger. Though unfortunately in my testing, this was still triggering.. so it might be a timing issue (0.99sec being too close to 1sec), or it might just be a bug in BetterTouchTool; not sure.

Could you copy & paste the config for these three triggers here (cmd+c/cmd+v)? Then I can have a look

1 Like

Just opened a bug report for this, so will copy/paste them there:

Edit: Shared them in this comment: Bug when using min/max hold time for keys configured with the same trigger key - #2 by devalias