-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from xtruan/develop
Merge to master
- Loading branch information
Showing
4 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pynput.keyboard import Key, Listener | ||
import time | ||
|
||
import utils.transform as transform | ||
|
||
csv_file = open('rec.csv', 'w') | ||
start = time.time() | ||
key_mode = 0 | ||
|
||
def on_press(key): | ||
global csv_file, start, key_mode | ||
if key_mode <= 0: | ||
key_mode = 1 | ||
|
||
end = time.time() | ||
out_str = transform.time_stringify(end - start) + ',SVO,2,90' | ||
print(out_str) | ||
csv_file.write(out_str + '\n') | ||
|
||
def on_release(key): | ||
global csv_file, start, key_mode | ||
if key_mode >= 0: | ||
key_mode = -1 | ||
|
||
end = time.time() | ||
out_str = transform.time_stringify(end - start) + ',SVO,2,00' | ||
print(out_str) | ||
csv_file.write(out_str + '\n') | ||
|
||
if key == Key.esc: | ||
# Stop listener | ||
return False | ||
if key == Key.backspace: | ||
print('--RESET--') | ||
csv_file.close() | ||
csv_file = open('rec.csv', 'w') | ||
start = time.time() | ||
|
||
# Collect events until released | ||
with Listener( | ||
on_press=on_press, | ||
on_release=on_release) as listener: | ||
listener.join() |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import time | ||
|
||
def time_convert(time_str): | ||
def time_floatify(time_str): | ||
time_list = time_str.split(':') | ||
return float(int(time_list[0]) * 3600 + int(time_list[1]) * 60 + float(time_list[2])) | ||
|
||
def time_stringify(time_secs): | ||
frac = float(time_secs) - int(time_secs) | ||
frac = int(frac * 1000) | ||
return time.strftime('%H:%M:%S', time.gmtime(time_secs)) + '.' + str(frac) | ||
|