Expose getKeysym and add keyboard test.

Related to issue Non-US keyboard layout option issue:
https://github.com/kanaka/noVNC/issues#issue/21
This commit is contained in:
Joel Martin 2011-01-03 12:34:41 -06:00
parent 56d9aa816b
commit bf5ee68828
2 changed files with 72 additions and 5 deletions

View File

@ -216,7 +216,7 @@ function constructor() {
}
/* Translate DOM key down/up event to keysym value */
function getKeysym(e) {
that.getKeysym = function(e) {
var evt, keysym;
evt = (e ? e : window.event);
@ -362,24 +362,24 @@ function onMouseMove(e) {
}
function onKeyDown(e) {
//Util.Debug("keydown: " + getKeysym(e));
//Util.Debug("keydown: " + that.getKeysym(e));
if (! conf.focused) {
return true;
}
if (c_keyPress) {
c_keyPress(getKeysym(e), 1);
c_keyPress(that.getKeysym(e), 1);
}
Util.stopEvent(e);
return false;
}
function onKeyUp(e) {
//Util.Debug("keyup: " + getKeysym(e));
//Util.Debug("keyup: " + that.getKeysym(e));
if (! conf.focused) {
return true;
}
if (c_keyPress) {
c_keyPress(getKeysym(e), 0);
c_keyPress(that.getKeysym(e), 0);
}
Util.stopEvent(e);
return false;

67
tests/keyboard.html Normal file
View File

@ -0,0 +1,67 @@
<html>
<head><title>Input Test</title></head>
<body>
<br><br>
Canvas:<br>
<canvas id="canvas" width="640" height="20"
style="border-style: dotted; border-width: 1px;">
Canvas not supported.
</canvas>
<br>
Results:<br>
<textarea id="messages" style="font-size: 9;" cols=80 rows=25></textarea>
</body>
<!--
<script type='text/javascript'
src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
-->
<script src="include/util.js"></script>
<script src="include/webutil.js"></script>
<script src="include/base64.js"></script>
<script src="include/canvas.js"></script>
<script>
var msg_cnt = 0;
var width = 400, height = 200;
var canvas;
function message(str) {
console.log(str);
msg_cnt++;
cell = $D('messages');
cell.innerHTML += msg_cnt + ": " + str + "\n";
cell.scrollTop = cell.scrollHeight;
}
function keyDown(evt) {
var e = (evt ? evt : window.event);
msg = "Dn: key:" + e.keyCode + " char:" + e.charCode + " which:" + e.which + " ksym:" + canvas.getKeysym(evt) + " alt:" + e.altKey + " shift:" + e.shiftKey + " ctrl:" + e.ctrlKey;
message(msg);
}
function keyUp(evt) {
var e = (evt ? evt : window.event);
msg = "Up: key:" + e.keyCode + " char:" + e.charCode + " which:" + e.which + " ksym:" + canvas.getKeysym(evt) + " alt:" + e.altKey + " shift:" + e.shiftKey + " ctrl:" + e.ctrlKey;
message(msg);
}
function keyPress(evt) {
var e = (evt ? evt : window.event);
msg = "Pr: key:" + e.keyCode + " char:" + e.charCode + " which:" + e.which + " ksym:" + canvas.getKeysym(evt) + " alt:" + e.altKey + " shift:" + e.shiftKey + " ctrl:" + e.ctrlKey;
message(msg);
}
window.onload = function() {
var c = $D('canvas');
canvas = new Canvas({'target' : c});
canvas.resize(width, height, true);
//canvas.start(keyPress);
Util.addEvent(document, 'keydown', keyDown);
Util.addEvent(document, 'keyup', keyUp);
Util.addEvent(document, 'keypress', keyPress);
message("Canvas initialized");
}
</script>
</html>