Hi, 

I am trying to code a rating scale where the marker moves one pixel when a 
key is pressed, but if the user holds the key down, the marker should move 
continuously until the key is released. Any ideas on how to do that? In the 
below code, VAS is a psychopy ratingScale object. 

############################ # Pakages # ############################
from psychopy.hardware import keyboard as kb
from psychopy import visual, event 
import pyglet
from pyglet.window import key as PygKey

############################ # Set up window # ############################
win = visual.Window(size=[800, 800],        # Screen size 
                    units="pix",            # The size and placement of 
stimuli is defined in pixels
                    monitor = "Monitor",    # Monitor can be set to 1 or 2
                    fullscr=False,          # Full Screen True or False
                    color=[0, 0, 0])        # Color of the background in 
the window  
                                            # [1,1,1] = White, [0,0,0] = 
Grey, [-1,-1,-1] = black


############################ # Set up pyglet # ############################
pyglet_keyboard=pyglet.window.key
keyboard = pyglet_keyboard.KeyStateHandler()
kb = kb.Keyboard()
win.winHandle.push_handlers(keyboard)
PygKeys = PygKey.KeyStateHandler()

############################ # Set up rating scale # 
############################

increment = 0.5                               # How fast the marker moves 
via button hold
SmallIncrement = 1                        # How far the button moves from 
quick press 
High = 100                                  # The max number on the scale 
Low = 0                                     # The min number on the scale 
Window = win                                # The window the rating scaled 
is placed in 
MarkerStart = 50                     
       # Marker starting point 

VAS = visual.RatingScale(win=Window,         
low = Low,
high = High, 
marker = 'triangle',
markerColor  = 'Black',
markerStart  = MarkerStart,
lineColor = 'black',
tickMarks = [0,100],
stretch = 1.5,
noMouse = True, 
leftKeys  = 'left', 
rightKeys = 'right',
showAccept = False, 
tickHeight = 1.5, 
acceptKeys = 'space',
textColor = 'Black')

rating_value= None
event.clearEvents()
#for frameN in range(10000):
while VAS.noResponse: 
    if PygKeys[PygKey.RIGHT]:
        VAS.markerPlacedAt += increment
    #if keyboard[pyglet_keyboard.RIGHT]: 
        #VAS.markerPlacedAt += SmallIncrement
    if PygKeys[PygKey.LEFT]:
        VAS.markerPlacedAt -= increment
    #if keyboard[pyglet_keyboard.LEFT]: 
        #VAS.markerPlacedAt -= SmallIncrement
    if VAS.markerPlacedAt > High:
        VAS.markerPlacedAt = High # do not allow marker to move outside the 
scale (above 100)
    elif VAS.markerPlacedAt < Low:
        VAS.markerPlacedAt = Low # do not allow marker to move outside the 
scale (below 0)
    VAS.draw()
    win.flip()
    rating_value = VAS.getRating() 
win.close()

If I comment out the elif statements, the marker moves in small increments. 
If I instead comment out the if statements (and change the elifs to ifs) 
the marker moves continuously, When I do not uncomment any lines, the 
marker moves continuously as well. Any help or advise would be greatly 
appreciated 

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyglet-users/c5c5a01f-5bfa-41a6-8585-8d8795345fdbn%40googlegroups.com.

Reply via email to