Karabiner-elements: [Question] - Is there a easier and more readable way to write complex modifications?

Created on 25 Aug 2017  路  4Comments  路  Source: pqrs-org/Karabiner-Elements

hey Guys, thanks for the awesome contribution.

Is there a easier and more readable way to write complex modifiers?

This json file is becoming huuuuge, and it's very easy to have a file with 2000+ lines...

stale

Most helpful comment

hey @thomasjachmann I managed it by doing a transpiler with ruby DSL... I will make it more friendly on my weekends and open the source soon.

it follows some examples

@description = "Application Mode"

@manipulators = []

@manipulators << when_press('left_control').activate_mode!('application_mode')

{
  h: 'Google Chrome',
  j: 'Sublime Text',
  k: 'Slack',
  l: 'iTerm'
}.each do |key, application_name|
  @manipulators << when_press(key).open_application!(application_name)
                                   .if_mode('application_mode', is: true)
end

@description = "Home Arrows Mode"

@manipulators = []

@manipulators << when_press('d').activate_mode!('home_arrows_mode')

{
   h: 'left_arrow' ,
   j: 'down_arrow' ,
   k: 'up_arrow'   ,
   l: 'right_arrow'
}.each do |key, to|
  @manipulators << when_press(key).trigger!(to)
                                   .if_mode('home_arrows_mode', is: true)

  @manipulators << when_press(key, 'left_command').trigger!(to, 'left_command')
                                                   .if_mode('home_arrows_mode', is: true)
end
[
{'0': ['a', 'left_control']},
{'4': ['e', 'left_control']}
].each do |from, to|
  @manipulators << when_press(from, 'fn').trigger!(to)
                                         .trigger!('vk_none')
                                         .if_mode('vi_mode', is: true)
                                         .if_mode('vi_visual_mode', is: false)

end

All 4 comments

Since I use a lot of custom modifier keys for the whole keyboard, mine's quite long as well. In #832, I asked about wildcards. Maybe you could upvote that ticket somehow if this would solve your problem as well. If enough users care about it, this might become a feature request worth handling.

hey @thomasjachmann I managed it by doing a transpiler with ruby DSL... I will make it more friendly on my weekends and open the source soon.

it follows some examples

@description = "Application Mode"

@manipulators = []

@manipulators << when_press('left_control').activate_mode!('application_mode')

{
  h: 'Google Chrome',
  j: 'Sublime Text',
  k: 'Slack',
  l: 'iTerm'
}.each do |key, application_name|
  @manipulators << when_press(key).open_application!(application_name)
                                   .if_mode('application_mode', is: true)
end

@description = "Home Arrows Mode"

@manipulators = []

@manipulators << when_press('d').activate_mode!('home_arrows_mode')

{
   h: 'left_arrow' ,
   j: 'down_arrow' ,
   k: 'up_arrow'   ,
   l: 'right_arrow'
}.each do |key, to|
  @manipulators << when_press(key).trigger!(to)
                                   .if_mode('home_arrows_mode', is: true)

  @manipulators << when_press(key, 'left_command').trigger!(to, 'left_command')
                                                   .if_mode('home_arrows_mode', is: true)
end
[
{'0': ['a', 'left_control']},
{'4': ['e', 'left_control']}
].each do |from, to|
  @manipulators << when_press(from, 'fn').trigger!(to)
                                         .trigger!('vk_none')
                                         .if_mode('vi_mode', is: true)
                                         .if_mode('vi_visual_mode', is: false)

end

@AlexVKO Great, let me know when it is published.

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.

Was this page helpful?
0 / 5 - 0 ratings