Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] OpenSesame virtual keyboard/numpad

edited March 2016 in OpenSesame

Hello!

In my experiment, I would like my participants to solve equations by clicking on an on-screen numpad.
Using the documentation (http://osdoc.cogsci.nl/2.8/python/keyboard/#keyboard.show_virtual_keyboard) I tried this in an inline scipt:

from openexp.keyboard import keyboard

my_keyboard = keyboard(self.experiment, keylist=['1', '2', '3'])
my_keyboard.show_virtual_keyboard(True)
response1, timestamp2 = my_keyboard.get_key()
response2, timestamp2 = my_keyboard.get_key()
my_keyboard.show_virtual_keyboard(False)

But nothing appears on the screen... In the 'keyboard.show_virtual_keyboard(visible=True)' function description it says that it does not work for all back-ends, but I tried all of them and it didn't work for any of them...

Does anyone knows how I can get an on-screen keyboard/numpad in OpenSesame?

Comments

  • edited 1:39PM

    Hi Merel,

    Right now the virtual keyboard is only applicable when running experiments on Android. What exactly do you want to do? Of course, you could implement something like an on-screen numpad with a bit of scripting.

    Cheers,
    Sebastiaan

  • edited March 2016

    Hi Sebastiaan,

    Thanks for your reaction! Ah, allright that explains why it didn't work. I have a new idea, maybe I can make it work by showing a numpad made out of butons a couple of times in a row, which gives the participants the 'illusion' of using a numpad. Because, it is not possible to press more than one button in the same widget right?

    Something like this:

    labelQuestion = widgets.label(form,text=equation)
    button0 = widgets.button(form, text='0', var='response')
    button1 = widgets.button(form, text='1', var='response')
    button2 = widgets.button(form, text='2', var='response')
    button3 = widgets.button(form, text='3', var='response')
    button4 = widgets.button(form, text='4', var='response')
    button5 = widgets.button(form, text='5', var='response')
    button6 = widgets.button(form, text='6', var='response')
    button7 = widgets.button(form, text='7', var='response')
    button8 = widgets.button(form, text='8', var='response')
    button9 = widgets.button(form, text='9', var='response')
    button_enter = widgets.button(form, text='enter', var='next')
    
    form.set_widget(labelQuestion, (0,0), colspan=4)
    
    form.set_widget(button0, (0,1))
    form.set_widget(button1, (1,1))
    form.set_widget(button2, (2,1))
    form.set_widget(button_enter, (3,1), rowspan = 2)
    form.set_widget(button3, (0,2))
    form.set_widget(button4, (1,2))
    form.set_widget(button5, (2,2))
    form.set_widget(button6, (0,3))
    form.set_widget(button7, (1,3))
    form.set_widget(button8, (2,3))
    form.set_widget(button9, (3,3))
    
    button_clicked = form._exec()
    
    
  • edited 1:39PM

    Hi Merel,

    Using a form to implement a numpad is not a bad idea!

    Because, it is not possible to press more than one button in the same widget right?

    Correct, but you can re-execute the form until the participant presses the enter button. And then you can use the return value of form._exec() to keep track of the response. I modified your script to illustrate the basic principle.

    Cheers!
    Sebastiaan

    from libopensesame import widgets
    
    form = widgets.form(exp, cols=[1,1,1,1], rows=[1,1,1,1],
        margins=(50,100,50,100), spacing=25)
    
    
    equation = '2 + 2 = ?'
    
    labelQuestion = widgets.label(form,text=equation)
    labelResponse = widgets.label(form,text='')
    button0 = widgets.button(form, text='0')
    button1 = widgets.button(form, text='1')
    button2 = widgets.button(form, text='2')
    button3 = widgets.button(form, text='3')
    button4 = widgets.button(form, text='4')
    button5 = widgets.button(form, text='5')
    button6 = widgets.button(form, text='6')
    button7 = widgets.button(form, text='7')
    button8 = widgets.button(form, text='8')
    button9 = widgets.button(form, text='9')
    button_enter = widgets.button(form, text='enter')
    
    form.set_widget(labelQuestion, (0,0), colspan=2)
    form.set_widget(labelResponse, (2,0), colspan=2)
    
    form.set_widget(button0, (0,1))
    form.set_widget(button1, (1,1))
    form.set_widget(button2, (2,1))
    form.set_widget(button_enter, (3,1), rowspan = 2)
    form.set_widget(button3, (0,2))
    form.set_widget(button4, (1,2))
    form.set_widget(button5, (2,2))
    form.set_widget(button6, (0,3))
    form.set_widget(button7, (1,3))
    form.set_widget(button8, (2,3))
    form.set_widget(button9, (3,3))
    
    var.response = ''
    while True:
        labelResponse.text = 'Response: %s' % var.response
        button_clicked = form._exec()
        if button_clicked == 'enter':
            break
        var.response = '%s%s' % (var.response, button_clicked)
    
  • edited 1:39PM

    Nice addition to show the participants their response! :) Maybe I should also add something that they can change their response if they accidentally press the wrong button, with a 'backspace' button or something like that. Otherwise it may be a bit confronting for them to see there response :)

  • edited 1:39PM

    Jeej adding an extra button and replace the while loop with this works :) :

    var.response = ''
    while True:
        labelResponse.text = 'Response: %s' % var.response
        button_clicked = form._exec()
    
        if button_clicked == 'enter':
            break
    
        if button_clicked == 'backspace':
            var.response = ''
        else:
            var.response = '%s%s' % (var.response, button_clicked)
    
Sign In or Register to comment.