WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 10-03-2017, 03:18 AM
tianmoran tianmoran is offline
Join Date: Nov 2016
Posts: 16
Smile viztask.waitkeydown

Hi guys,

I have some question in using viztask.waitKeyDown. I know it returns a 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
acc = 0
data = open('data.txt', 'a')
trialData = "%s\t%s\n" %(acc,RT)

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!!
Reply With Quote
Old 10-09-2017, 02:05 PM
Jeff Jeff is offline
WorldViz Team Member
Join Date: Aug 2008
Posts: 2,471
Here is a simple example:

import viz
import viztask


def keytask():
	while True:
		d = yield viztask.waitKeyDown(None) 
		key = d.key 
		if key == 'j': 
			print 'j pressed' 
			print 'some other key pressed'
viztask.schedule( keytask() )
Reply With Quote

clearkeys, waitkeydown

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 01:28 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2023, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC