1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

現在のデフォルトレイヤーを取得する方法

Last updated at Posted at 2020-12-11

やりたいこと

現在のデフォルトレイヤーが何番か知りたい

方法

get_highest_layer(default_layer_state) または古いqmk_firmwareの場合は biton32(default_layer_state) を使用する(実装は同じ)。以下のような感じ。

enum layers {
  LAYER_PC,
  LAYER_MAC
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  switch (biton32(default_layer_state)) {
    case LAYER_PC:
      tap_code(KC_MHEN);
      break;
    case LAYER_MAC: 
      tap_code(KC_LANG2);
      break;
    default:
      SEND_STRING("ILLEGAL STATE!");
  }
}

実際に動く例: https://github.com/bigwheel/qmk_firmware/blob/cbc18cf8/keyboards/ble_micro_pro/keymaps/sensible/keymap.c#L125-L129

参考

https://github.com/qmk/qmk_firmware/blob/master/tmk_core/common/action_layer.c#L52
など。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?