psychopy.org | Reference | Downloads | Github

ioHub getKeys() only logging modifier keys


#1

Hi, all,

I’m trying to implement user text input using ioHub, and it seems that the getKeys() function is only logging keyboard events for modifier keys (alt, shift, etc) and is completely ignoring all other keys. It doesn’t even return an empty tuple when these keys are pressed; it’s absolutely unresponsive. This problem arises whether I’m using my code or the demos.

I’m running the standalone Psychopy build, vers. 1.84.1, on El Capitan (10.11.6). Psychopy and Terminal have both been authorized under the accessibility settings. I’m using my MacBook’s built-in keyboard.

If anyone has any clues or suggestions for a fix, I’d be so, so grateful.

–K

EDIT: In a last-ditch effort, I re-installed Psychopy and the issue has vanished. Marking as solved.


Capturing event times during StaticPeriod
#2

Hi
if you try the following code does it work? Do you get all the keys you press?
Emanuele

from psychopy import visual
from psychopy.iohub import launchHubServer

io = launchHubServer()
keyboard = io.devices.keyboard

mywin = visual.Window((800, 600), monitor='testMonitor', units='deg')
text = visual.TextStim(mywin, text='Press a key', pos=(0, 0), height=.5, bold=True, colorSpace='rgb', color='white')

keyout = []

while keyout != "escape":
    key = keyboard.getKeys()
    if key != []:
        keyname = key[0]
        keyout = keyname.key
        text.setText('Press ' + keyout)
    text.draw()
    mywin.flip()

#3

I tried code very much like this when I was experimenting, and I went ahead and tried your code as well–still no luck. It only responds to modifier keys (lshift, rshift, cmd, etc.) and completely ignores letters and numbers.


#4

Hi,

I’m having the same problem with ioHub getKeys() only logging/returning modifier keys (lshift, rshift, lcmd, rcmd, etc.). As per k_wood, I tried uninstalling and reinstalling psychopy, but no luck. Note that I’m running psychopy via anaconda 2.7 and so did “pip uninstall psychopy” followed by “pip install psychopy”. I’m running version 1.90.2 on MacOS 10.13.5

Any suggestions?

Thanks so much,
Daniel

In case it’s helpful, here’s my dummy code:


from psychopy import core, visual
from psychopy.iohub import launchHubServer 


### SETUP WINDOW
# define default window parameters
winInfo={'fullscr':False, 'screen':0,
    'monitor':'mainMonitor',
    'allowGUI':False, 'allowStencil': False, 'units': 'norm',
    'color':[-1,-1,-1], 'colorSpace':'rgb',
    'blendMode':'avg', 'useFBO':True, 'checkTiming':False}

# instantiate window
win = visual.Window(**winInfo)

# draw frames -- this is a test that frame are drawing
for i in range(100):
    print('window flip # {}'.format(i))
    win.flip()

io=launchHubServer()

keyboard = io.devices.keyboard

keyout = []
while keyout != "escape":
    key = keyboard.getKeys()
    if key != []:
        keyname = key[0]
        keyout = keyname.key
        print('Pressed {}'.format(keyout))
        # text.setText('Press ' + keyout)
    # text.draw()
    win.flip()

### I've also tried the version below:
# run = True
# while run:
#     for event in keyboard.getEvents():
#         print(event)
#         if event.key == "q":
#             run = False
#     io.clearEvents()
    
    
io.quit()


win.close()
core.quit()

#5

UPDATE:
I tried using standalone psychopy 1.90.3, which I freshly downloaded and installed. I ran the demo iohub > keyboard.py.

Again, the program only responded to modifier keys. However, there was a new interesting behavior. If pressed a standard key in addition to the modifier key, the standard key would be reported in the onscreen demo under the bottom header “event.getKeys():”, whereas only the modifier key would be reported in the top header “event.key():”. Again, nothing was reported if I pressed the standard key in isolation.

Any advice?

Thanks very much!
Daniel


#6

I SOLVED this issue by adding the terminal app to the Mac OS accessibility list:
see: http://mizage.com/help/accessibility.html#10.9

iohub now registers all key presses.

Thanks!
Daniel