evan-liu / karabiner.ts Goto Github PK
View Code? Open in Web Editor NEWWrite Karabiner-Elements configuration in TypeScript
Home Page: https://evan-liu.github.io/karabiner.ts
License: MIT License
Write Karabiner-Elements configuration in TypeScript
Home Page: https://evan-liu.github.io/karabiner.ts
License: MIT License
https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-evaluation-priority/
if there are multiple manipulators which change the same key, the manipulator placed at the top is applied and other manipulators are ignored
rule().manipulators([
map().to(),
...condition(ifVar, [])
])
karabiner.ts/src/config/layer.ts
Line 154 in 40f160e
This code above enforces layers with modifiers do not allow keymaps to have modifiers but does not handle the case when both need to have optional any modifiers
This code produces valid configuration for example and is required to allow common shortcuts like command + left_arrow etc for the remapped keys
layer('semicolon', 'semicolon-down')
.modifiers({ optional: 'any' })
.manipulators([
withModifier({ optional: 'any'})([
map('l').toAfterKeyUp('right_arrow'),
withMapper({
j: 'left_arrow',
k: 'down_arrow',
l: 'right_arrow',
i: 'up_arrow',
})((k, v) => map(k).to(v as ToKeyCode)),
]),
]),
[error] [console_user_server] parse error in ~/.config/karabiner/karabiner.json: `complex_modifications` error: `manipulators` is missing or empty in {"description":"","manipulators":[]}
Need to check empty manipulators
when build.
to('vk_none')
See Karabiner from.simultaneous
And other FromEvent formats.
mapDoubleTap(1).to('q', 'β')
Hi,
Recently installed karabiner.ts and I want to use it in place of skhd for yabai. skhd binds shortcuts to shell commands and I thought I could do the same using karabiner.ts as well. But it doesnβt work. Can anyone help me understand if there's anything wrong with it. My config looks like this.
import { to$ } from 'karabiner.ts'
export const yabai = {
j: to$('yabai -m window --focus south'),
k: to$('yabai -m window --focus north'),
h: to$('yabai -m window --focus west'),
l: to$('yabai -m window --focus east'),
y: to$('yabai -m space --mirror y-axis'),
x: to$('yabai -m space --mirror x-axis'),
o: to$('yabai -m config focus_follows_mouse autofocus'),
t: to$('yabai -m window --toggle float --grid 4:4:1:1:2:2'),
m: to$('yabai -m window --toggle zoom-fullscreen'),
e: to$('yabai -m space --balance'),
p: to$('yabai -m window --space prev'),
n: to$('yabai -m window --space next'),
r: to$('yabai --restart-service'),
s: to$('yabai --start-service'),
c: to$('yabai --stop-service'),
}
and then in index.ts
as
const rules = [
duoLayer('q', 'w')
.manipulators(yabai)
.notification('yabai mode')
.toIfActivated(toLocalSound('pop')),
]
writeToProfile('Default', rules, {
'basic.simultaneous_threshold_milliseconds': 100,
'duo_layer.threshold_milliseconds': 200,
'duo_layer.notification': true,
})
Modifier alias (command
, option
, control
, shift
) can be used as from.modifiers and to.modifiers but not key_code
.
Map a group of manipulators in the same way with a mapper function.
withMapper((k) => map(k).to(''))(['a', 'b', 'c'])
e.g display_brightness_increment
, fastforward
?βͺ
for { optional: ["caps_lock"] }
??
for { optional: ["any"] }
Maybe I'm holding it wrong, but I thought I'd report this
deno run --allow-env --allow-read --allow-write main.ts
error: Uncaught ReferenceError: require is not defined
return require('node:path').join(
^
at Object.karabinerConfigFile (https://deno.land/x/[email protected]/output.ts:16:5)
at writeToProfile (https://deno.land/x/[email protected]/output.ts:61:51)
at file:///Users/kai/projects/karabiner/main.ts:13:1
looks like the output thing tries to import node:path
and barfs. everything else seem working
console.log(rule("stuff").manipulators([...]).build())
this works fine
Thanks @riccardoNovaglia for giving up the karabiner-ts
npm package.
Similar to withCondition()
, to add modifiers to a group of manipulators.
typeSequence('console.log()β')
Support single-character key_code
, key alias, and shifted punctuations.
It is currently impossible to express it in TypeScript. So the parameter will only be able to be string
; and a runtime/build-time error instead of complier error for unsupported characters.
There can be a mapper parameter to support mapping customised characters to ToEvent
.
typeSequence('ββ', {
'β': toKey('β', 'β'),
})
First of all, thank you for the effort you put into making this tool!
I need help as I thought I had understood this tool but I haven't, or rather I just can't set up what I need, and here's what I need:
I tried this code:
mapDoubleTap('left_command', 'optionalAny').to('f16').singleTap(toKey('f15'))
The first and second requirements work. The third - which is the most important one - doesn't.
What am I doing wrong?
So existing karabiner users can import their config.
I had played around a bit in the Playground and wondered why one feature wasn't working. Could it be that the Playground is not using the latest version? When I run the ts script locally it works as expected.
simlayer().enableLayer(key?: key | key[])
First off thanks for this amazing DSL for karabiner! Havent used it for a few years cause I bought a moonlander, but recently got a macbook so its nice to see how much nicer karabiner itself got and how nice it is to configure with this project.
I find myself wanting a layer modifier that I think is not currently covered by the options that exist, but I think should be possible with the karabiner spec. Essentially my problem is typing fast and it not recognizing the key as a press because it is still down when I hit the next key.
SimLayers do the opposite of what I want, they make me type fast to get the layer, but I want the layer only when I am going slow and to be the normal key when fast. So after XXX ms of holding a key down I want to set the layer var to 1, if I release before that it should still be 0. I think this should be possible with to_delayed_action. I might try adding this manually first and then can maybe try to make a PR unless this is something it would be easy for you to add, or if you have any other ideas for this.
Amazing project!
I created a layer with arrow keys that I activate with F, so I have:
layer('f', 'f-arrow-mode').manipulators([
map('i').to('β'),
map('j').to('β'),
map('l').to('β'),
map('k').to('β'),
])
Is there a way to let these mappings work orthogonally with modifiers such as Shift or Option? Would I even be able to remap such modifiers to D, S etc? Would be awesome to be able to hold down S+D+F then hit J to select words backwards just with the homerow keys.
To support Hyper Key sublayer from @mxstbr
First off, thank you so much for all the work you've done. I've been using a different Karabiner config generator for a bit over a year but yours has dramatically reduced the amount of code I had and made it easier to read.
In my current config, I use both the "left_option" and "right_option" keys as layer keys themselves, without any additional keys. From what I've gathered this isn't really possible although I've kinda made it work
Thanks in advanced for the help!
So basically, I want to map fn+backspace to option+backspace.
Dug around in the types and found that the symbol β« represents backspace.
But when I try to use it, it doesn't recognize and i get a type error, and also when I build, it doesn't seem to work.
That is my code currently:
rule('fn delete word').manipulators([
// config key mappings
map('fn', 'β«').to('right_option', 'β«'),
]),
How would I go about doing this?
Right now, there are 2 options to have sides in modifiers:
['left_command', 'right_option']
{ left: 'β', right: 'β₯' }
Both are too verbose compared to 'ββ₯'
.
There is an issue on Goku discussing the idea of <
and >
for left_
and right_
, so it could be
<β>β₯
or >ββ₯>
However, it is too hard to express in TypeScript.
I am thinking about the first character instead
<ββ₯
for left_command, left_option
>ββ₯
for right_command, right_option
['<β', '>β₯']
for left_command, right_option
Or use the letter l
and r
instead of <
and >
lββ₯
for left_command, left_option
rββ₯
for right_command, right_option
['lβ', 'rβ₯']
for left_command, right_option
Or maybe is { l: 'β', r: 'β₯' }
good enough if not used often?
A consideration is that with the Hyper Key, there can be some accidental system diagnostics that are run. They use a lot of memory and take quite a while. Perhaps they should be disabled by default?
See this article for details:
e.g "System Settingsβ
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.