Commit bf5ee688 authored by Joel Martin's avatar Joel Martin

Expose getKeysym and add keyboard test.

Related to issue Non-US keyboard layout option issue:
https://github.com/kanaka/noVNC/issues#issue/21
parent 56d9aa81
...@@ -216,7 +216,7 @@ function constructor() { ...@@ -216,7 +216,7 @@ function constructor() {
} }
/* Translate DOM key down/up event to keysym value */ /* Translate DOM key down/up event to keysym value */
function getKeysym(e) { that.getKeysym = function(e) {
var evt, keysym; var evt, keysym;
evt = (e ? e : window.event); evt = (e ? e : window.event);
...@@ -362,24 +362,24 @@ function onMouseMove(e) { ...@@ -362,24 +362,24 @@ function onMouseMove(e) {
} }
function onKeyDown(e) { function onKeyDown(e) {
//Util.Debug("keydown: " + getKeysym(e)); //Util.Debug("keydown: " + that.getKeysym(e));
if (! conf.focused) { if (! conf.focused) {
return true; return true;
} }
if (c_keyPress) { if (c_keyPress) {
c_keyPress(getKeysym(e), 1); c_keyPress(that.getKeysym(e), 1);
} }
Util.stopEvent(e); Util.stopEvent(e);
return false; return false;
} }
function onKeyUp(e) { function onKeyUp(e) {
//Util.Debug("keyup: " + getKeysym(e)); //Util.Debug("keyup: " + that.getKeysym(e));
if (! conf.focused) { if (! conf.focused) {
return true; return true;
} }
if (c_keyPress) { if (c_keyPress) {
c_keyPress(getKeysym(e), 0); c_keyPress(that.getKeysym(e), 0);
} }
Util.stopEvent(e); Util.stopEvent(e);
return false; return false;
......
<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>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment