-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpitest.py
executable file
·60 lines (42 loc) · 1.08 KB
/
pitest.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
#! /usr/bin/python
import random
import RPi.GPIO as GPIO
import json
import time
inputpins = [4, 14, 15, 17]
testlog = []
class BCMKeyboard:
def __init__(self):
self.activekeys = []
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
for i in inputpins:
GPIO.setup(i, GPIO.OUT, initial=GPIO.LOW)
def delay(self):
time.sleep(abs(random.gauss(0.01,.05)))
def pressKey(self, key):
self.delay()
GPIO.output(key, GPIO.HIGH)
def releaseKey(self, key):
self.delay()
GPIO.output(key, GPIO.LOW)
def releaseAnyKey(self):
self.releaseKey(random.choice(self.activekeys))
def arePressed(self):
return len(self.activekeys)
Ck = BCMKeyboard()
for i in range(255):
chosen = random.sample(inputpins, random.choice(range(1,len(inputpins)+1)))
random.shuffle(chosen)
testlog.append(chosen)
with open("testlog.json", "w") as f:
json.dump(testlog, f)
for i in testlog:
Ck.pressKey(i.pop(0))
while len(i) > 0:
if Ck.arePressed() > 1 and random.choice([True,False]):
Ck.releaseAnyKey()
else:
Ck.pressKey(i.pop())
while Ck.arePressed() > 0:
Ck.releaseAnyKey()