Skip to content

Instantly share code, notes, and snippets.

@hasumikin
Created May 6, 2022 02:51
Show Gist options
  • Save hasumikin/ff9fe9315eb7c61d7cabe35cb87d8d9b to your computer and use it in GitHub Desktop.
Save hasumikin/ff9fe9315eb7c61d7cabe35cb87d8d9b to your computer and use it in GitHub Desktop.
Simulating "Grave Escape" feature of QMK
class Keyboard
def grave_escape
index = @keycodes.index(KEYCODE.index(:KC_ESCAPE).chr)
if index
if (@modifier & 0b00010001) > 0 # CTRL
# Do nothing so that "SHIFT+CTRL+ESCAPE" opens Task Manager
elsif (@modifier & 0b00100010) > 0 # SHIFT
@keycodes[index] = KEYCODE.index(:KC_GRAVE).chr
elsif (@modifier & 0b10001000) > 0 # GUI
@keycodes[index] = KEYCODE.index(:KC_GRAVE).chr
@modifier &= 0b01110111
# However, this is going to send "releasing" of :KC_LGUI(:KC_RGUI)
# then the Windows menu appears after all.
# I don't know how QMK handles the problem :thinking_face:
end
end
end
# ## Replacing methods with const increases runtime performance
# def grave_escape
# index = @keycodes.index(")") # KC_ESCAPE
# if index
# if (@modifier & 0b00010001) > 0
# # do nothing
# elsif (@modifier & 0b00100010) > 0
# @keycodes[index] = "5" # KC_GRAVE
# elsif (@modifier & 0b10001000) > 0
# @keycodes[index] = "5" # KC_GRAVE
# @modifier &= 0b01110111
# end
# end
# end
end
puts "Example for meishi2"
kbd = Keyboard.new
kbd.init_pins(
[ 6, 7 ], # row0, row1
[ 28, 27 ] # col0, col1
)
kbd.add_layer :default, %i(
KC_LSFT
KC_LGUI
KC_LCTL
KC_ESCAPE
)
kbd.before_report { kbd.grave_escape }
kbd.start!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment