pqrs-org / KE-complex_modifications

Karabiner-Elements complex_modifications rules
https://ke-complex-modifications.pqrs.org/
The Unlicense
1.31k stars 1.1k forks source link

Virtual Keys #759

Closed algrw-c closed 2 years ago

algrw-c commented 4 years ago

Hello, is there any way to change from one key to a Personalised virtual key? I want to remap every key in a keyboard so i can program the keys whit Keyboard Maestro but don't want the key to be writen when i press it, just be detected by Keyboard Mestro

MuhammedZakir commented 4 years ago

You can do it with a shell_command [1] by triggering macros with AppleScript [2]. But, why not simply use "Hot Key" trigger? [3]

[1] https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/to/shell-command/ [2] https://wiki.keyboardmaestro.com/trigger/Script [3] https://wiki.keyboardmaestro.com/trigger/Hot_Key

Edit: Looking what others did will help you - https://github.com/pqrs-org/KE-complex_modifications/search?q=osascript.

algrw-c commented 4 years ago

Thanks for answering! I been using Hot Key trigger, but when i use it it activates the key too, I use this for Final Cut, and had space as one hot key, that run a macro, but when i press it the video resumes. I don't know much about programing so dont understand the 1 link or the second, sorry

MuhammedZakir commented 4 years ago

Try this:

{
  "title": "Trigger Keyboard Maestro macro",
  "rules": [
    {
      "description": "Final Cut -> Space trigger someMacro",
      "manipulators": [
        {
          "type": "basic",
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": ["^com.apple.finder$"]
            }
          ],
          "from": {
            "key_code": "spacebar",
            "modifiers": {
              "optional": ["any"]
            }
          },
          "to": [
            {
              "shell_command": "osascript -e 'tell application \"Keyboard Maestro Engine\"' -e 'do script \"Name or UID of your Macro\"' -e 'end tell'"
            }
          ]
        }
      ]
    }
  ]
}
  1. Change "Name or UID of your Macro" to your Macro's name/UID. To get UID, see https://wiki.keyboardmaestro.com/manual/Menus#Copy_UUID.

  2. In bundle_identifiers, change com.apple.finder to your application's bundle identifier. You can also use "file path" of an app. You can find the bundle identifier and file path of an app in KarabinerElemnts menu > Launch EventViewer > Frontmost Application tab (EventViewer is also available as an app - Karabiner-EventViewer.app).

FYI, you can add more than one bundle identifier in bundle_identifiers. Same goes for file_paths. You may also use both of them. See https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/frontmost-application/.

  1. Save this in a file named someName.json in ~/.config/karabiner/assets/complex_modifications/ folder.

  2. Import it - KarabinerElements Preferences > Complex modifications > Add rule.

Note: In shell_command, there are two ways to execute AppleScript:

  1. No additional file, but might not be easy: Add each statement after -e command. If there is any double quotes(") or backslash(\) in it, you will have to escape it by prepending it with backslash. Just like what I have done.
  2. Save AppleScript in a file with .scpt extension and you can use it like this - osascript path/to/yourScript.scpt.

This may help you - https://wiki.keyboardmaestro.com/manual/Scripting#AppleScript.


I don't know much about programing so dont understand the 1 link or the second, sorry

You don't need to know programming. Just read! It REALLY helps. That's how I came to know all these stuffs. And I am pretty sure many others are also like this. So, just read! 🙂

Edit:

I been using Hot Key trigger, but when i use it it activates the key too, I use this for Final Cut, and had space as one hot key, that run a macro, but when i press it the video resumes.

You should notify Keyboard Maestro devs about this.

algrw-c commented 4 years ago

Should this work? I am testing it whit alfred Captura de Pantalla 2020-10-22 a la(s) 17 57 55 Captura de Pantalla 2020-10-22 a la(s) 17 57 41 Captura de Pantalla 2020-10-22 a la(s) 17 57 31 PD: I am trying it whit the integrated space bar Edit: This is working but while i am in Finder only, how do i so to use it in other apps?

MuhammedZakir commented 4 years ago

Edit: This is working but while i am in Finder only, how do i so to use it in other apps?

Second point mentioned above:

--snip--

  1. In bundle_identifiers, change com.apple.finder to your application's bundle identifier. You can also use "file path" of an app. You can find the bundle identifier and file path of an app in KarabinerElemnts menu > Launch EventViewer > Frontmost Application tab (EventViewer is also available as an app - Karabiner-EventViewer.app).

FYI, you can add more than one bundle identifier in bundle_identifiers. Same goes for file_paths. You may also use both of them. See https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/frontmost-application/.

--snip--

So, if you want this modification in, say Firefox, then add Firefox's bundle identifier or it's path.

"conditions": [
  {
    "type": "frontmost_application_if",
    "bundle_identifiers": [
      "^com.apple.finder$",
      "^org.mozilla.firefox$"
    ]
  }
]

You may also use file path or both of them. It's up to you. If you want it to work in all apps, then just remove conditions.


A quick note on bundle_identifiers and file_paths: KarabinerElements consider these as regex and in regex,

It is valid to write without these, but it may match other apps. See

**tl;dr - just add caret at the start and dollar at the end of a bundle identifier or file path.


This [1] may help you in case you want to use modifier keys.

[1] https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/from/modifiers/

algrw-c commented 4 years ago

Thank you very much, From where to where do i have to remove to take the conditions? And, is there a way to write complex modification in the same file? just to keep it more organised And last, is there anyway i can Thank you enought?

MuhammedZakir commented 4 years ago

Thank you very much,

You're welcome! :-)

From where to where do i have to remove to take the conditions?

You can consider everything as key: value pair. If you want to remove a key, remove the corresponding value; if it's inside brackets, remove up to and including the matching bracket. In the above code, conditions's value is an array (square bracket), so remove everything up to and including the matching square bracket. You must also remove the trailing comma. So this is what you have to remove:

"conditions": [
  {
    "type": "frontmost_application_if",
    "bundle_identifiers": ["^com.apple.finder$"]
  }
],

For those who are unfamiliar to JSON, it might be slightly difficult to find the matching bracket in plain text editor . So I highly recommend you to use a good editor (TextMate, Visual Studio Code, etc.). In these, you will get highlighting, you can collapse what's inside matching brackets(blocks) and/or you can jump to matching bracket. This really helps, especially when editing large file. Use these [1][2] to get an idea of what I am telling.

[1] https://jsonformatter.org/json-editor [2] https://jsonformatter.curiousconcept.com/ (only formatting and block folding)

And, is there a way to write complex modification in the same file? just to keep it more organised

Yes. All of your settings, modifications, including imported ones, are saved in ~/.config/karabiner/karabiner.json. If you want to, you can directly edit it. But, when editing it, use a JSON validator before saving to prevent potential errors. In case you messed up, you can find backups at ~/.config/karabiner/automatic_backups/.

And last, is there anyway i can Thank you enought?

https://karabiner-elements.pqrs.org/docs/pricing/ :-)

algrw-c commented 4 years ago

https://karabiner-elements.pqrs.org/docs/pricing/ :-)

Consider it Done ;)

algrw-c commented 4 years ago

One last question (Or I think) How do i convine them so they apear toghether instead of these: Captura de Pantalla 2020-10-24 a la(s) 17 41 57

(By toghether i mean in the same folder/class)

MuhammedZakir commented 4 years ago

Add your modification rules in rules array, which will be shown under the corresponding title.

{
  "title": "Trigger Keyboard Maestro macro",
  "rules": [
    {
      "description": "rule 1",
      "manipulators": [
        {
          ...
        }
      ]
    },
    {
      "description": "rule 2",
      "manipulators": [
        {
          ...
        }
      ]
    }
  ]
}

^This will result in:

https://karabiner-elements.pqrs.org/docs/json/root-data-structure/#custom-json-file-in-configkarabinerassetscomplex_modifications


In short, whenever you see an array([ ] - square brackets), you can consider it as a list and hence, can add more than one item. Example:

etc...

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.