forked from rbino/softmech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
softmech.py
executable file
·69 lines (57 loc) · 1.75 KB
/
softmech.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
#!/usr/bin/env python
from pyxhook import HookManager
from random import choice
import os
from sdl2 import *
from sdl2.ext.compat import byteify
from sdl2.sdlmixer import *
sounddir = "CMStormTKBlue"
pressed = {}
def handle_event_down(event):
if (event.Key not in pressed or not pressed[event.Key]):
if event.Key == "space":
playrandom(spacedowns)
elif event.Key == "Return":
playrandom(returndowns)
else:
playrandom(downs)
pressed[event.Key] = True
def handle_event_up(event):
if event.Key == "space":
playrandom(spaceups)
elif event.Key == "Return":
playrandom(returnups)
else:
playrandom(ups)
pressed[event.Key] = False
def playrandom(sounds):
Mix_PlayChannel(-1, choice(sounds), 0)
SDL_Init(SDL_INIT_AUDIO)
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 256)
sounds = os.listdir(sounddir)
downs = [Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8'))
for f in sounds
if "down.wav" in f]
ups = [Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8'))
for f in sounds
if "up.wav" in f]
spacedowns = [Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8'))
for f in sounds
if "down_space.wav" in f]
spaceups = [Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8'))
for f in sounds
if "up_space.wav" in f]
returndowns = [Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8'))
for f in sounds
if "down_return.wav" in f]
returnups = [Mix_LoadWAV(byteify(sounddir + os.sep + f, 'utf-8'))
for f in sounds
if "up_return.wav" in f]
hm = HookManager()
hm.HookKeyboard()
hm.KeyDown = handle_event_down
hm.KeyUp = handle_event_up
try:
hm.run()
except:
print("\nClick clack! Bye!")