Last active
January 4, 2022 01:02
-
-
Save pallove/d8ccf1d5912a5a4af0414e4924dbb6f9 to your computer and use it in GitHub Desktop.
because the vscode use Fn keys(debug, rename, Go to...), and the karabiner is so heavy, so i do some work on Hammerspoon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- place the snippets in your ~/.hammerspoon/init.lua | |
local sys_key = { | |
[3] = {pos = 1, key = 'F1'}, -- BRIGHTNESS_DOWN | |
[2] = {pos = 2, key = 'F2'}, -- BRIGHTNESS_UP | |
[22] = {pos = 5, key = 'F5'}, -- ILLUMINATION_DOWN | |
[21] = {pos = 6, key = 'F6'}, -- ILLUMINATION_UP | |
[20] = {pos = 7, key = 'F7'}, -- REWIND | |
[16] = {pos = 8, key = 'F8'}, -- PLAY | |
[14] = {pos = 9, key = 'F9'}, -- FAST | |
[7] = {pos = 10, key = 'F10'}, -- MUTE | |
[1] = {pos = 11, key = 'F11'}, -- SOUND_DOWN | |
[0] = {pos = 12, key = 'F12'}, -- SOUND_UP | |
} | |
local app_fn = { | |
['Code'] = tonumber('010011111111', 2), -- flag pos, active F1-F12 keys exclude F1,F3,F4 | |
--['xxx'] = tonumber('100000000000', 2), -- flag pos, active only F1 key | |
} | |
local function tb_keys(tb) | |
local t = {} | |
for k in pairs(tb) do | |
table.insert(t, k) | |
end | |
return t | |
end | |
hs.eventtap.new({hs.eventtap.event.types.systemDefined}, function(event) | |
local keyobj = event:systemKey() | |
local keycode = keyobj.keyCode | |
-- capture the system code print(hs.inspect.inspect(keyobj)) | |
if not keycode then return false end | |
local current_app = hs.application.frontmostApplication() | |
for name, mask in pairs(app_fn) do | |
if name == current_app:name() then | |
local t = sys_key[keycode] | |
if t then | |
if 1 << (12 - t.pos) & mask == 0 then return false end | |
local key_event = hs.eventtap.event.newKeyEvent(tb_keys(event:getFlags()), t.key, keyobj.down) | |
key_event:post(current_app) | |
return true | |
end | |
end | |
end | |
end):start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment