1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-10 18:50:54 +00:00
This commit is contained in:
jonathanoroberts 2017-05-11 15:29:43 +00:00 committed by GitHub
commit c6bee25cad

View File

@ -17,10 +17,11 @@ psychoJS._keyBuffer = []
psychoJS.event._keyDownHandler = function(e) {
//console.log("key press: code=" + e.code + " key=" + e.key);
//console.log("key press: code=" + e.code + " key=" + e.key + " keyCode=" + e.keyCode);
psychoJS._keyBuffer.push({
code : e.code,
key : e.key,
keyCode: e.keyCode,
timestamp : psychoJS.core.getTime()
});
//console.log("keys pressed : " + JSON.stringify(psychoJS._keyBuffer));
@ -30,6 +31,19 @@ psychoJS.event.clearKeys = function() {
psychoJS._keyBuffer = [];
}
psychoJS.event._keyMap = {
left : 37,
up: 38,
right : 39,
down: 40,
escape : 27,
space : 32
};
psychoJS.event._reverseKeyMap = {};
for(keyName in psychoJS.event._keyMap) {
psychoJS.event._reverseKeyMap[psychoJS.event._keyMap[keyName]] = keyName;
}
/**
* Get the list keys that were pressed.
* @param keyList - undefined or []. Allows the user to specify a set of keys to check for. Only keypresses from this set of keys will be removed from the keyboard buffer. If the keyList is None all keys will be checked and the key buffer will be cleared completely.
@ -56,6 +70,9 @@ psychoJS.event.getKeys = function(attribs) {
if (index < 0) {
index = keyList.indexOf(key.key);
}
if (index < 0) {
index = keyList.indexOf(psychoJS.event._reverseKeyMap[key.keyCode]);
}
if (index >= 0) {
keyId = keyList[index];
}