Thread: key duration
View Single Post
  #3  
Old 06-11-2021, 01:43 AM
Roy Roy is offline
Member
 
Join Date: Dec 2019
Posts: 9
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
Reply With Quote