WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   key duration (https://forum.worldviz.com/showthread.php?t=6359)

Roy 04-06-2021 11:27 AM

key duration
 
Hi,

How to get duration between a key down and key up during task?

During watching some VR scene (or VR avatar) for 5 sec, I want to measure participants' key-press duration (how long participant presses the key). viztask.waitKeyUp may be suitable, but it terminates the VR scene showing.

kennethkarthik 04-19-2021 03:03 PM

Hey Roy,

If you don't want yield statements terminating your scene, I would suggest using the onkeydown and onkeyup function in the vizact library. Use the respective up and down functions to log the time using viz.tick() in global variables and then find the difference to calculate the elapsed time. This should occur without causing any disruption in the scene being run.

Hope it helps.

Best,
Kenneth

Roy 06-11-2021 01:43 AM

Hi Kenneth,

Please see the codes which use the onkeydown&up methods as below.

Code:

def keyDown():
        global start
        start = viz.tick()
        print ('key pressed: ' + str(start))
       
def keyUp():
        global start, end, keyTime
        end = viz.tick()
        keyTime = end - start
        print ('key released: ' + str(end))
        print ('key duration: ' + str(keyTime))

As the interactive says below, the key duration (0.0275349) becomes wrong because the duration is calculated by the difference between the keyup time (20.1739211) and last keydown time (20.1463862).
The key duration should be calculated by the first keydown time (19.2442121).
How to fix it?

Quote:

key pressed: 19.2442121
key pressed: 19.7575294
key pressed: 19.7922581
key pressed: 19.8203054
key pressed: 19.8484828
key pressed: 19.8831089
key pressed: 19.9171247
key pressed: 19.9451206
key pressed: 19.9799625
key pressed: 20.0280531
key pressed: 20.0560133
key pressed: 20.0905871
key pressed: 20.1188808
key pressed: 20.1463862
key released: 20.1739211
key duration: 0.0275349


All times are GMT -7. The time now is 03:05 PM.

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