vany5921
Published

ATOM Board

This is a project that uses Atom Matrix to customize shortcut keys, which is convenient for users to set key combinations

AdvancedProtip5 hours2,398
ATOM Board

Things used in this project

Story

Read more

Code

Keymap

Textile
KEY_MAP = {     
    'LBUTTON'               : 0x01,     # 
    'RBUTTON'               : 0x02,     # 
    'CANCEL'                : 0x03,     # Ctrl+Pause Break
    'MBUTTON'               : 0x04,     # 
    'XBUTTON1'              : 0x05,     # X1
    'XBUTTON2'              : 0x06,     # X2
    'BACK'                  : 0x08,     # Backspace
    'TAB'                   : 0x09,     # Tab
    'CLEAR'                 : 0x0C,     # ClearNum Lock5
    'RETURN'                : 0x0D,     # Enter
    'SHIFT'                 : 0x10,     # Shift
    'CONTROL'               : 0x11,     # Ctrl
    'MENU'                  : 0x12,     # Alt
    'ALT'                   : 0x12,     
    'PAUSE'                 : 0x13,     # Pause Break
    'CAPITAL'               : 0x14,     # Caps Lock
    'KANA'                  : 0x15,     # Input Method Editor IME
    'HANGEUL'               : 0x15,     # 
    'HANGUL'                : 0x15,     # 
    'JUNJA'                 : 0x17,     # junja
    'FINAL'                 : 0x18,     # final
    'HANJA'                 : 0x19,     # 
    'KANJI'                 : 0x19,     # 
    'ESCAPE'                : 0x1B,     # Esc
    'ESC'                   : 0x1B,     
    'CONVERT'               : 0x1C,     # IME convert
    'NONCONVERT'            : 0x1D,     # IME nonconvert
    'ACCEPT'                : 0x1E,     # IME accept
    'MODECHANGE'            : 0x1F,     # IME mode change request
    'SPACE'                 : 0x20,     # SpaceBar
    'PRIOR'                 : 0x21,     # Page Up
    'NEXT'                  : 0x22,     # Page Down
    'END'                   : 0x23,     # End
    'HOME'                  : 0x24,     # Home
    'LEFT'                  : 0x25,     # 
    'UP'                    : 0x26,     # 
    'RIGHT'                 : 0x27,     # 
    'DOWN'                  : 0x28,     # 
    'SELECT'                : 0x29,     # Select
    'PRINT'                 : 0x2A,     # Print
    'EXECUTE'               : 0x2B,     # Excute
    'SNAPSHOT'              : 0x2C,     # Print Screen
    'INSERT'                : 0x2D,     # Insert
    'DELETE'                : 0x2E,     # Delete
    'HELP'                  : 0x2F,     # Help
    '0'                     : 0x30,     
    '1'                     : 0x31,     
    '2'                     : 0x32,     
    '3'                     : 0x33,     
    '4'                     : 0x34,     
    '5'                     : 0x35,     
    '6'                     : 0x36,     
    '7'                     : 0x37,     
    '8'                     : 0x38,     
    '9'                     : 0x39,     
    ':'                     : 0x3A,     
    ';'                     : 0x3B,     
    '<'                     : 0x3C,     
    '='                     : 0x3D,     
    '>'                     : 0x3E,     
    '?'                     : 0x3F,     
    '@'                     : 0x40,     
    'A'                     : 0x41,     
    'B'                     : 0x42,     
    'C'                     : 0x43,     
    'D'                     : 0x44,     
    'E'                     : 0x45,     
    'F'                     : 0x46,     
    'G'                     : 0x47,     
    'H'                     : 0x48,     
    'I'                     : 0x49,     
    'J'                     : 0x4A,     
    'K'                     : 0x4B,     
    'L'                     : 0x4C,     
    'M'                     : 0x4D,     
    'N'                     : 0x4E,     
    'O'                     : 0x4F,     
    'P'                     : 0x50,     
    'Q'                     : 0x51,     
    'R'                     : 0x52,     
    'S'                     : 0x53,     
    'T'                     : 0x54,     
    'U'                     : 0x55,     
    'V'                     : 0x56,     
    'W'                     : 0x57,     
    'X'                     : 0x58,     
    'Y'                     : 0x59,     
    'Z'                     : 0x5A,     
    'LWIN'                  : 0x5B,     # windows
    'RWIN'                  : 0x5C,     # windows
    'APPS'                  : 0x5D,     # 
    'SLEEP'                 : 0x5F,     # Sleep
    'NUMPAD0'               : 0x60,     # 0
    'NUMPAD1'               : 0x61,     # 1
    'NUMPAD2'               : 0x62,     # 2
    'NUMPAD3'               : 0x63,     # 3
    'NUMPAD4'               : 0x64,     # 4
    'NUMPAD5'               : 0x65,     # 5
    'NUMPAD6'               : 0x66,     # 6
    'NUMPAD7'               : 0x67,     # 7
    'NUMPAD8'               : 0x68,     # 8
    'NUMPAD9'               : 0x69,     # 9
    'MULTIPLY'              : 0x6A,     # *
    'ADD'                   : 0x6B,     # +
    'SEPARATOR'             : 0x6C,     # Separator
    'SUBTRACT'              : 0x6D,     # -
    'DECIMAL'               : 0x6E,     # .
    'DIVIDE'                : 0x6F,     # /
    'F1'                    : 0x70,     
    'F2'                    : 0x71,     
    'F3'                    : 0x72,     
    'F4'                    : 0x73,     
    'F5'                    : 0x74,     
    'F6'                    : 0x75,     
    'F7'                    : 0x76,     
    'F8'                    : 0x77,     
    'F9'                    : 0x78,     
    'F10'                   : 0x79,     
    'F11'                   : 0x7A,     
    'F12'                   : 0x7B,     
    'F13'                   : 0x7C,     
    'F14'                   : 0x7D,     
    'F15'                   : 0x7E,     
    'F16'                   : 0x7F,     
    'F17'                   : 0x80,     
    'F18'                   : 0x81,     
    'F19'                   : 0x82,     
    'F20'                   : 0x83,     
    'F21'                   : 0x84,     
    'F22'                   : 0x85,     
    'F23'                   : 0x86,     
    'F24'                   : 0x87,     
    'NUMLOCK'               : 0x90,     # Num Lock
    'SCROLL'                : 0x91,     # Scroll Lock
    'OEM_NEC_EQUAL'         : 0x92,     # NEC PC-9800 =
    'OEM_FJ_JISHO'          : 0x92,     # Fujitsu/OASYS 'Dictionary'
    'OEM_FJ_MASSHOU'        : 0x93,     # Fujitsu/OASYS 'Unregister word'
    'OEM_FJ_TOUROKU'        : 0x94,     # Fujitsu/OASYS 'Register word'
    'OEM_FJ_LOYA'           : 0x95,     # Fujitsu/OASYS 'Left OYAYUBI'
    'OEM_FJ_ROYA'           : 0x96,     # Fujitsu/OASYS 'Right OYAYUBI'
    'LSHIFT'                : 0xA0,     # ShiftSHIFT
    'SHIFT'                 : 0xA0,     
    'RSHIFT'                : 0xA1,     # ShiftSHIFT
    'LCONTROL'              : 0xA2,     # CtrlCONTROL
    'CTRL'                  : 0xA2,     
    'RCONTROL'              : 0xA3,     # CtrlCONTROL
    'LMENU'                 : 0xA4,     # AltMENU
    'RMENU'                 : 0xA5,     # AltMENU
    'BROWSER_BACK'          : 0xA6,     # 
    'BROWSER_FORWARD'       : 0xA7,     # 
    'BROWSER_REFRESH'       : 0xA8,     # 
    'BROWSER_STOP'          : 0xA9,     # 
    'BROWSER_SEARCH'        : 0xAA,     # 
    'BROWSER_FAVORITES'     : 0xAB,     # 
    'BROWSER_HOME'          : 0xAC,     # 
    'VOLUME_MUTE'           : 0xAD,     # 
    'VOLUME_DOWN'           : 0xAE,     # 
    'VOLUME_UP'             : 0xAF,     # 
    'MEDIA_NEXT_TRACK'      : 0xB0,     # 
    'MEDIA_PREV_TRACK'      : 0xB1,     # 
    'MEDIA_STOP'            : 0xB2,     # 
    'MEDIA_PLAY_PAUSE'      : 0xB3,     # /
    'LAUNCH_MAIL'           : 0xB4,     # 
    'LAUNCH_MEDIA_SELECT'   : 0xB5,     # 
    'LAUNCH_APP1'           : 0xB6,     # 1
    'LAUNCH_APP2'           : 0xB7,     # 2
    'OEM_1'                 : 0xBA,     # ';:'
    'OEM_PLUS'              : 0xBB,     # '=+'
    'OEM_COMMA'             : 0xBC,     # ',<'
    'OEM_MINUS'             : 0xBD,     # '-_'
    'OEM_PERIOD'            : 0xBE,     # '.>'
    'OEM_2'                 : 0xBF,     # '/?'
    'OEM_3'                 : 0xC0,     # '`~'
    'OEM_4'                 : 0xDB,     # '[{'
    'OEM_5'                 : 0xDC,     # '|'
    'OEM_6'                 : 0xDD,     # ']}'
    'OEM_7'                 : 0xDE,     # ''"'
    'OEM_8'                 : 0xDF,     # 
    'OEM_AX'                : 0xE1,     # AX'AX'
    'OEM_102'               : 0xE2,     # RT 102-key"<>""|"
    'ICO_HELP'              : 0xE3,     # 
    'ICO_00'                : 0xE4,     # 00
    'PROCESSKEY'            : 0xE5,     # IME PROCESS
    'ICO_CLEAR'             : 0xE6,     # Clear
    'PACKET'                : 0xE7,     # 
    'OEM_RESET'             : 0xE9,     # 
    'OEM_JUMP'              : 0xEA,     # 
    'OEM_PA1'               : 0xEB,     # 
    'OEM_PA2'               : 0xEC,     # 
    'OEM_PA3'               : 0xED,     # 
    'OEM_WSCTRL'            : 0xEE,     # 
    'OEM_CUSEL'             : 0xEF,     # 
    'OEM_ATTN'              : 0xF0,     # 
    'OEM_FINISH'            : 0xF1,     # 
    'OEM_COPY'              : 0xF2,     # 
    'OEM_AUTO'              : 0xF3,     # 
    'OEM_ENLW'              : 0xF4,     # 
    'OEM_BACKTAB'           : 0xF5,     # 
    'ATTN'                  : 0xF6,     # Attn
    'CRSEL'                 : 0xF7,     # CrSel
    'EXSEL'                 : 0xF8,     # ExSel
    'EREOF'                 : 0xF9,     # Erase EOF
    'PLAY'                  : 0xFA,     # Play
    'ZOOM'                  : 0xFB,     # Zoom
    'NONAME'                : 0xFC,     # 
    'PA1'                   : 0xFD,     # PA1
    'OEM_CLEAR'             : 0xFE      # Clear
}

Master

C/C++
No preview (download only).

Slave

C/C++
No preview (download only).

Atomboard

Python
import win32api
import win32con
import time
import ctypes
import os
import serial
import sys
from keymap import *

def keydownup(num):
    MapVirtualKey = ctypes.windll.user32.MapVirtualKeyA
    time.sleep(0.4)
    win32api.keybd_event(num, MapVirtualKey(num, 0), 0, 0)
    time.sleep(0.2)
    win32api.keybd_event(num, MapVirtualKey(num, 0), win32con.KEYEVENTF_KEYUP, 0)

try:
    PORT = sys.argv[1]
except:
    exit('Please specify the serial port number, eg: ./keyboard2.exe COM1')

device = serial.Serial(PORT, 115200, timeout=1000)

while True:
    data = device.readline()
    if len(data) > 0:
        try:
            payload = data.decode('ascii')
            print (payload)
            buf = payload.strip().split('|')
            head = buf[0]
            actype = buf[1]
            action = buf[2]
            if 'Action' in head:
                if 'KeyEvent' in actype:
                    MapVirtualKey = ctypes.windll.user32.MapVirtualKeyA
                    keys = action.split('+')
                    for key in keys:
                        if key in KEY_MAP:
                            win32api.keybd_event(KEY_MAP[key], MapVirtualKey(KEY_MAP[key], 0), 0, 0)
                        else:
                            print('Invalid key: ' + key)
                    time.sleep(0.4)
                    for key in keys:
                        if key in KEY_MAP:
                            win32api.keybd_event(KEY_MAP[key], MapVirtualKey(KEY_MAP[key], 0), win32con.KEYEVENTF_KEYUP, 0)

                elif 'Execute' in actype:
                    try:
                        cmds = action.split('+')
                        if len(cmds) == 1:
                            win32api.ShellExecute(0, 'open', action, '', '', 1)
                        elif len(cmds) == 2:
                            win32api.ShellExecute(0, cmds[0], cmds[1], '', '', 1)
                        elif len(cmds) == 3:
                            win32api.ShellExecute(0, cmds[0], cmds[1], '', cmds[2], 1)
                        else:
                            win32api.ShellExecute(0, cmds[0], cmds[1], cmds[2], cmds[3], 1)
                    except Exception as err:
                        print(err)
        except:
            pass
# win32api.ShellExecute(0, 'open', r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe", '', r"C:\Users\tongy\Desktop", 1)
# win32api.ShellExecute(0, 'open', r"C:\Users\tongy\AppData\Local\Programs\Microsoft VS Code\Code.exe", '', r"C:\Users\tongy\Desktop", 1)
# win32api.ShellExecute(0, 'open', r"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe", 'bash', '/', 1)

AtomBoard_Win64

JavaScript
No preview (download only).

Credits

M5Stack

Posted by vany5921

Comments