Skip to content

Commit e544c20

Browse files
committed
Add --remap-key command
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent af96787 commit e544c20

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

EXAMPLES.md

+36
Original file line numberDiff line numberDiff line change
@@ -380,3 +380,39 @@ sudo framework_tool --rgbkbd 2 0xFF0000
380380
> sudo framework_tool --stylus-battery
381381
Stylus Battery Strength: 77%
382382
```
383+
384+
## Remap keyboard
385+
386+
Note that the keyboard matrix on Framework 12 and Framework 13 are
387+
different.
388+
The scancodes are the same.
389+
390+
- Left-Ctrl 0x0014
391+
- Left-Alt 0x0014
392+
- Tab 0x0058
393+
394+
### Framework 12
395+
396+
```
397+
# Remap capslock key as left-ctrl
398+
> framework_tool --remap-key 6 15 0x0014
399+
400+
# Swap left-ctrl and alt
401+
> framework_tool --remap-key 1 14 0x0011
402+
> framework_tool --remap-key 6 13 0x0014
403+
```
404+
405+
### Framework 13
406+
407+
```
408+
# Remap capslock key as left-ctrl
409+
> framework_tool --remap-key 4 4 0x0014
410+
411+
# Swap left-ctrl and alt
412+
> framework_tool --remap-key 1 12 0x0011
413+
> framework_tool --remap-key 1 3 0x0014
414+
```
415+
416+
### Framework 16
417+
418+
It's not controlled by the EC, use https://keyboard.frame.work.

framework_lib/src/commandline/clap_std.rs

+14
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ struct ClapCli {
181181
#[arg(long)]
182182
kblight: Option<Option<u8>>,
183183

184+
/// Set keyboard backlight percentage or get, if no value provided
185+
#[arg(long, value_parser=maybe_hex::<u16>)]
186+
#[clap(num_args = 3)]
187+
remap_key: Vec<u16>,
188+
184189
/// Set the color of <key> to <RGB>. Multiple colors for adjacent keys can be set at once.
185190
/// <key> <RGB> [<RGB> ...]
186191
/// Example: 0 0xFF000 0x00FF00 0x0000FF
@@ -333,6 +338,14 @@ pub fn parse(args: &[String]) -> Cli {
333338
1 => Some((args.charge_rate_limit[0], None)),
334339
_ => None,
335340
};
341+
let remap_key = match args.remap_key.len() {
342+
3 => Some((
343+
args.remap_key[0] as u8,
344+
args.remap_key[1] as u8,
345+
args.remap_key[2],
346+
)),
347+
_ => None,
348+
};
336349

337350
Cli {
338351
verbosity: args.verbosity.log_level_filter(),
@@ -392,6 +405,7 @@ pub fn parse(args: &[String]) -> Cli {
392405
fp_led_level: args.fp_led_level,
393406
fp_brightness: args.fp_brightness,
394407
kblight: args.kblight,
408+
remap_key,
395409
rgbkbd: args.rgbkbd,
396410
tablet_mode: args.tablet_mode,
397411
touchscreen_enable: args.touchscreen_enable,

framework_lib/src/commandline/mod.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub struct Cli {
181181
pub fp_led_level: Option<Option<FpBrightnessArg>>,
182182
pub fp_brightness: Option<Option<u8>>,
183183
pub kblight: Option<Option<u8>>,
184+
pub remap_key: Option<(u8, u8, u16)>,
184185
pub rgbkbd: Vec<u64>,
185186
pub tablet_mode: Option<TabletModeArg>,
186187
pub touchscreen_enable: Option<bool>,
@@ -804,6 +805,15 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
804805
} else if let Some(Some(kblight)) = args.kblight {
805806
assert!(kblight <= 100);
806807
ec.set_keyboard_backlight(kblight);
808+
} else if let Some(None) = args.kblight {
809+
print!("Keyboard backlight: ");
810+
if let Some(percentage) = print_err(ec.get_keyboard_backlight()) {
811+
println!("{}%", percentage);
812+
} else {
813+
println!("Unable to tell");
814+
}
815+
} else if let Some((row, col, scanset)) = args.remap_key {
816+
print_err(ec.remap_key(row, col, scanset));
807817
} else if !args.rgbkbd.is_empty() {
808818
if args.rgbkbd.len() < 2 {
809819
println!(
@@ -819,13 +829,6 @@ pub fn run_with_args(args: &Cli, _allupdate: bool) -> i32 {
819829
});
820830
ec.rgbkbd_set_color(start_key, colors.collect()).unwrap();
821831
}
822-
} else if let Some(None) = args.kblight {
823-
print!("Keyboard backlight: ");
824-
if let Some(percentage) = print_err(ec.get_keyboard_backlight()) {
825-
println!("{}%", percentage);
826-
} else {
827-
println!("Unable to tell");
828-
}
829832
} else if let Some(tablet_arg) = &args.tablet_mode {
830833
let mode = match tablet_arg {
831834
TabletModeArg::Auto => TabletModeOverride::Default,

0 commit comments

Comments
 (0)