I usually keep all F1,F2,etc. keys as media control keys.But when I code in Visual Studio Code ,I want to auto switch it to standard keys. How can I make it? I tried to use complex modifications rules ,but it doesn't work.
There is my rules :
{
"title": "VSCode",
"rules": [
{
"description": "Swap fn keys",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "display_brightness_decrement",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f1"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "display_brightness_increment",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f2"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "mission_control",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f3"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "launchpad",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f4"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "illumination_decrement",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f5"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "illumination_increment",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f6"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "rewind",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f7"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "play_or_pause",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f8"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "fastforward",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f9"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "mute",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f10"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "volume_decrement",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f11"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "volume_increment",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "f12"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"com\\.microsoft\\.VSCode"
]
}
]
}
]
}
]
}
I had the same issue, the reason is rule order: simple -> complex -> F-Keys.
The key pressed f1 is changed to display_brightness_decrement after your rule runs. So you just need to catch f1 and return f1+fn.
{
"title": "VSCode",
"rules": [
{
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f1"
},
"to": [
{
"key_code": "f1",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f2"
},
"to": [
{
"key_code": "f2",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f3"
},
"to": [
{
"key_code": "f3",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f4"
},
"to": [
{
"key_code": "f4",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f5"
},
"to": [
{
"key_code": "f5",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f6"
},
"to": [
{
"key_code": "f6",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f7"
},
"to": [
{
"key_code": "f7",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f8"
},
"to": [
{
"key_code": "f8",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f9"
},
"to": [
{
"key_code": "f9",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f10"
},
"to": [
{
"key_code": "f10",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f11"
},
"to": [
{
"key_code": "f11",
"modifiers": [
"fn"
]
}
],
"type": "basic"
},
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.microsoft\\.VSCode"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "f12"
},
"to": [
{
"key_code": "f12",
"modifiers": [
"fn"
]
}
],
"type": "basic"
}
]
}
]
}
Thank you very much !
Are you able to then press fn + F1 to regain the opposite behavior (i.e. decrease brightness in Mac)?
I can't seem to do that, though this rule is otherwise behaving as expected.
Are you able to then press
fn + F1to regain the opposite behavior (i.e. decrease brightness in Mac)?I can't seem to do that, though this rule is otherwise behaving as expected.
That's because when you use this modification, fx and fn+fx are sending the same keys in VS Code. If you want to use fn+fx for special features with this modification, you will also have to map each combination (fn+f1, fn+f2, ...) to those keys. You can get keycodes of those keys from EventViewer.
Most helpful comment
I had the same issue, the reason is rule order: simple -> complex -> F-Keys.
The key pressed
f1is changed todisplay_brightness_decrementafter your rule runs. So you just need to catchf1and returnf1+fn.