PDA

View Full Version : viztask.waitkeydown


tianmoran
10-03-2017, 03:18 AM
Hi guys,

I have some question in using viztask.waitKeyDown. I know it returns a viz.data object with the key value and time. But I do not know how to do 'if' judgments with the key value. Here are the codes:

d = yield viztask.waitKeyDown(None)
Key = d.key
RT = d.time - startTime
if Key == 'J':
acc = 1
else:
acc = 0
data = open('data.txt', 'a')
trialData = "%s\t%s\n" %(acc,RT)
data.write(trialData)

I would like to know if the key pressed is 'J' or not. How should I write this line?

And another question is, is there any way to clear all key pressed before I do the judgment?

Many thanks!!

Jeff
10-09-2017, 02:05 PM
Here is a simple example:

import viz
import viztask

viz.go()

def keytask():

while True:
d = yield viztask.waitKeyDown(None)
key = d.key
if key == 'j':
print 'j pressed'
else:
print 'some other key pressed'

viztask.schedule( keytask() )