Created
December 13, 2023 06:29
-
-
Save phuang1024/c8946bacba3f696af1338915b8a718fe to your computer and use it in GitHub Desktop.
Type with a piano keyboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "44": "esc", | |
| "45": "z", | |
| "46": "q", | |
| "47": "a", | |
| "48": "x", | |
| "49": "w", | |
| "50": "s", | |
| "51": "e", | |
| "52": "d", | |
| "53": "c", | |
| "54": "r", | |
| "55": "v", | |
| "56": "f", | |
| "57": "g", | |
| "58": "t", | |
| "59": "b", | |
| "60": " ", | |
| "61": "y", | |
| "62": "h", | |
| "63": "u", | |
| "64": "n", | |
| "65": "j", | |
| "66": "i", | |
| "67": "m", | |
| "68": "o", | |
| "69": "k", | |
| "70": "p", | |
| "71": "l", | |
| "72": ",", | |
| "73": ";", | |
| "74": ".", | |
| "75": "'", | |
| "76": "/", | |
| "77": "enter", | |
| "79": "backspace", | |
| "80": "9", | |
| "82": "0" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import mido | |
| import pyautogui | |
| inputs = mido.get_input_names() | |
| for i, inp in enumerate(inputs): | |
| print(i, inp) | |
| choice = int(input("Choose input: ")) | |
| midi_input = mido.open_input(inputs[choice]) | |
| with open("mapping.json", "r") as f: | |
| mapping = json.load(f) | |
| shift_status = False | |
| try: | |
| while True: | |
| msg = midi_input.receive() | |
| if msg.type == "note_on": | |
| index = str(msg.note) | |
| if index in mapping: | |
| value = mapping[index] | |
| pyautogui.press(value) | |
| print(msg.note, value) | |
| elif msg.type == "control_change" and msg.control == 64: | |
| new_status = msg.value >= 15 | |
| if new_status != shift_status: | |
| shift_status = new_status | |
| print("Shift:", shift_status) | |
| if shift_status: | |
| pyautogui.keyDown("shift") | |
| else: | |
| pyautogui.keyUp("shift") | |
| except KeyboardInterrupt: | |
| pyautogui.keyUp("shift") | |
| raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment