View Single Post
  #2  
Old 05-04-2012, 06:24 AM
hrm hrm is offline
Member
 
Join Date: Feb 2012
Posts: 2
Hello there,
An update.
So using either A) viz.callback or B) viztask.schedule functions work in getting some response from the button box presses. -- see below

BUT I can't seem to get these keypresses from the button box to move the views using if-else conditions
viz.key.isDown('2'):#(viz.KEY_UP):
Should I be using viz.key.isDown with the button box keys? The function works for keyboard keys though...
I also did get this error:
"before Glyph::subload(): detected OpenGL error: invalid enumerant"
i) I am not sure if it the inability to move the trigger based on a button box key press is related to that error.
ii) would lack of RAM be an issue?

Any help/advise would be appreciated!
Thanks in advance.
May

--------------------------------------------------------------------
A)
import viz
import viztask

viz.go()

keyDisplay = viz.addText( 'key pressed: ', viz.SCREEN , pos=(0.25,0.5,0) )
keyDisplay.fontSize(30)
keyDisplay2 = viz.addText( 'keys 1,2, or 3 pressed: ', viz.SCREEN , pos=(0.25,0.75,0) )
keyDisplay2.color(viz.RED)
keyDisplay2.fontSize(30)

global key
def mykeyinput(key):
ShowData(viz.tick(),key)
viz.callback(viz.KEYDOWN_EVENT, mykeyinput)


def ShowData(currenttime,key):#(k):#(currenttime,key,k ):
global data
data = 'time: '+ str(currenttime) + ' keypress: "' + key + '"'
print data
kpress = 'Key " '+key+ ' "'
keyDisplay.message(kpress)#( 'keypress: ' + str(k.key) )
if key=='1':
keyDisplay2.message('yo!')#(kpress)
elif key=='2':
keyDisplay2.message('yoyo!')#(kpress)
elif key=='3':
keyDisplay2.message('yoyoyo!')#(kpress)
elif key=='4':
keyDisplay2.message('yoyoyoyo!')#(kpress)
else:
keyDisplay2.message('oooooooooooooooooooo!')#(kpre ss)

B)
import viz
import viztask

viz.go()

keyDisplay = viz.addText( 'key pressed: ', viz.SCREEN , pos=(0.25,0.5,0) )
keyDisplay.fontSize(30)
keyDisplay2 = viz.addText( 'keys 1,2, or 3 pressed: ', viz.SCREEN , pos=(0.25,0.75,0) )
keyDisplay2.color(viz.RED)
keyDisplay2.fontSize(30)

def mykeyinput():#(key):
global k
while True:
k=yield viztask.waitKeyDown(None)
# Calls the function SaveData and hands it the current time and key
#ShowData(viz.tick(),key,k)
ShowData(k)
#displayKeypress(k)
# Defines a callback for keyboard events
#viz.callback(viz.KEYDOWN_EVENT, mykeyboard)
viztask.schedule(mykeyinput)

def ShowData(k):#(currenttime,key,k):
global data
#data = 'time: '+ str(currenttime) + ' keypress: "' + key + '"'
data = "Key '"+k.key+"' was pressed at time",k.time
print data
kpress = 'Key " '+ k.key+' "'
#displayKey = viz.addText(str(kpress), viz.SCREEN , pos=(0.1,0.5,0) )
keyDisplay.message(kpress)#( 'keypress: ' + str(k.key) )
if k.key=='1':
keyDisplay2.message('yo!')#(kpress)
elif k.key=='2':
keyDisplay2.message('yoyo!')#(kpress)
elif k.key=='3':
keyDisplay2.message('yoyoyo!')#(kpress)
else:
keyDisplay2.message('oooooooooooooooooooo!')#(kpre ss)
Reply With Quote