Skip to content

Instantly share code, notes, and snippets.

@cattaka
Created April 26, 2018 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cattaka/0e39fec7398ece93463b067367a9b72a to your computer and use it in GitHub Desktop.
Save cattaka/0e39fec7398ece93463b067367a9b72a to your computer and use it in GitHub Desktop.
Replace all keybind of IntelliJ (including android studio), meta <> control
# Replace all keybind of IntelliJ (including android studio)
# meta <> control
#
# How to use
#
# extract original keymaps from resource.jar
# $ unzip $PATH_TO_INTELLI_J/lib/resources.jar keymaps/\*
# $ python android_studio_swap_key.py -i keymaps/Mac\ OS\ X\ 10.5+.xml -o swapped.xml
import xml.etree.ElementTree as ET
import argparse
def swap_control_meta(elem):
if elem.tag != "keyboard-shortcut" or elem.attrib is None:
return
values = elem.attrib["first-keystroke"]
if values is None:
return
new_values = values.replace("meta", "m_e_t_a").replace("control", "meta").replace("m_e_t_a", "control")
elem.attrib["first-keystroke"] = new_values
for child in elem.getchildren():
swap_control_meta(child)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
# Input Arguments
parser.add_argument(
'-i',
help='Target keymaps xml',
required=True
)
parser.add_argument(
'-o',
help='Output keymaps xml',
required=True
)
args = parser.parse_args()
tree = ET.parse(args.i)
for child in tree.iter():
swap_control_meta(child)
tree.write(args.o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment