-
Notifications
You must be signed in to change notification settings - Fork 0
/
lkm.py
92 lines (71 loc) · 2.95 KB
/
lkm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#-*- coding: utf-8 -*-
#!/usr/bin/python
import sys
import subprocess
import configparser
import winsound
from time import sleep
from launchpad import Launchpad
from winkeyevent import PressKey, ReleaseKey
DEBUG = True
ACTION_TYPE = {"0" : "KEYIN", "1" : "EXEC", "2" : "NOTE", "3" : "WAVE", "9": "SPECIAL"}
settings = configparser.ConfigParser()
settings.read("settings.ini")
midiInPort = settings['midi']['midiInPort']
midiOutPort = settings['midi']['midiOutPort']
lp = Launchpad()
if DEBUG is True:
il, ol = lp.getDeviceList()
print("now available input is {}".format(il))
print("now available output is {}".format(ol))
print("inport is {}, outport is {}".format(midiInPort, midiOutPort))
result = lp.connect(midiInPort, midiOutPort)
if result is True:
doloop = True
while doloop:
try:
msg = lp.getMsg()
if msg:
key = str(msg['message'][0]) + str(msg['message'][1])
try:
typeForAction, action = settings['action'][key].split(',')
if DEBUG is True:
print("key is in settings.ini")
print("type is {}, key is [{}], action is {}".format(ACTION_TYPE[typeForAction], key, action))
#윈도우 키입력 신호 발생
if ACTION_TYPE[typeForAction] == "KEYIN":
PressKey(int(action, 0))
ReleaseKey(int(action, 0))
#지정된 명령어 실행
elif ACTION_TYPE[typeForAction] == "EXEC":
subprocess.Popen(action, creationflags=subprocess.DETACHED_PROCESS)
#노트 연주
elif ACTION_TYPE[typeForAction] == "NOTE":
lp.playNote(int(action, 0), 112, 0.1)
#음성파일 연주
elif ACTION_TYPE[typeForAction] == "WAVE":
winsound.PlaySound(action, winsound.SND_FILENAME)
#현재 프로그램 기능으로 사용할 항목
elif ACTION_TYPE[typeForAction] == "SPECIAL":
if key == "15336":
doloop = False
raise KeyboardInterrupt
else:
pass
except KeyError as e:
if DEBUG is True:
print("key[{}] is not in settings.ini".format(key))
print(e)
except ValueError as e:
if DEBUG is True:
print(e)
except OSError as e:
if DEBUG is True:
print(e)
except KeyboardInterrupt as e:
if DEBUG is True:
print("user keyInterrupt")
print(e)
doloop = False
lp.disconnect()
sys.exit()