Hi Moshe,
So here is one solution, there are other simpler ones, but this one is immersive and rather flexible.
We then force all keyboard input into it by keeping it always in focus.
We pick an existing stimulus and update it with the content of the input every time that it changes, the stimulus is chosen according to it's handle as set into "stimHandle' in the custom event object.
Finally we trigger an even each time a change is made to the input.
This event can be caught and responded to from you interactions.
Following is the custom event:
{
handle: 'input',
stimHandle: 'word-stim',
on: function(inputObj, canvas, stream){
var $listener = stream();
// create hidden element
var element = document.createElement('input');
var stim = canvas.querySelector('[data-handle=' + inputObj.stimHandle + ']');
element.style.opacity = 0;
element.value = stim.innerHTML;
canvas.appendChild(element);
// make sure element is always in focus.
element.addEventListener('blur', focus);
focus();
element.addEventListener('input', input);
$listener.end.map(function(){
element.removeEventListener('blur',focus);
element.removeEventListener('input',input);
element.remove();
});
return $listener;
function focus(){ element.focus(); }
function input(e){
stim.innerHTML = e.target.value;
$listener(e);
}
}
}
And this is how you can respond to it within your interactions (in this case, save the value of the input into trial.data.value):
{
conditions: [{type:'inputEquals', value:'input'}],
actions: [
// set the results of the input into trial.data
function(action,event,trial){trial.data.value = event.event.target.value;}
]
}
Finally, you can use a regular input and interaction to submit/end the trail.
Good luck,
Elad