Ctrl Lock and Alt Lock support:

You can prevent unnecessary interference from the client when you type keys
such as "Alt + F" or "Ctrl + Alt + Backspace". And you can also type
"AltGr + Ctrl + 9" to enter "Ctrl + ]" with a German keyboard.
This commit is contained in:
Hirokazu Takahashi 2012-12-12 12:09:22 +09:00
parent e37086c1e1
commit 3a2027e4be
4 changed files with 72 additions and 15 deletions

View File

@ -600,6 +600,7 @@ checkEvents = function() {
// The status of the VNC server side key modifers. // The status of the VNC server side key modifers.
var remote_status = {shift: false, ctrl: false, alt: false, altgr: false}; var remote_status = {shift: false, ctrl: false, alt: false, altgr: false};
var softKeyState = {ctrlKey: false, altKey: false};
keyPress = function(keysym, down, km) { keyPress = function(keysym, down, km) {
var arr = []; var arr = [];
@ -615,13 +616,15 @@ keyPress = function(keysym, down, km) {
// Send key events for modifiers to the vnc server when: // Send key events for modifiers to the vnc server when:
// 1. the status of modifers have been changed // 1. the status of modifers have been changed
// 2. this is a repeated keydown event for a modifer // 2. this is a repeated keydown event for a modifer
if (remote_status.ctrl !== km.ctrlKey || keysym === 0xFFE3) { var ctrlKey = km.ctrlKey || softKeyState.ctrlKey;
arr = arr.concat(keyEvent(0xFFE3, km.ctrlKey)); // CTRL var altKey = km.altKey || softKeyState.altKey;
remote_status.ctrl = km.ctrlKey; if (remote_status.ctrl !== ctrlKey || keysym === 0xFFE3) {
arr = arr.concat(keyEvent(0xFFE3, ctrlKey)); // CTRL
remote_status.ctrl = ctrlKey;
} }
if (remote_status.alt !== km.altKey || keysym === 0xFFE9) { if (remote_status.alt !== altKey || keysym === 0xFFE9) {
arr = arr.concat(keyEvent(0xFFE9, km.altKey)); // ALT arr = arr.concat(keyEvent(0xFFE9, altKey)); // ALT
remote_status.alt = km.altKey; remote_status.alt = altKey;
} }
if (remote_status.altgr !== km.altgrKey || keysym === 0xFE03) { if (remote_status.altgr !== km.altgrKey || keysym === 0xFE03) {
arr = arr.concat(keyEvent(0xFE03, km.altgrKey)); // ALTGR arr = arr.concat(keyEvent(0xFE03, km.altgrKey)); // ALTGR
@ -1916,6 +1919,10 @@ that.sendKey = function(code, down) {
ws.send(arr); ws.send(arr);
}; };
that.updateSoftKeyState = function(name, value) {
softKeyState[name] = value;
};
that.clipboardPasteFrom = function(text) { that.clipboardPasteFrom = function(text) {
if (rfb_state !== "normal") { return; } if (rfb_state !== "normal") { return; }
//Util.Debug(">> clipboardPasteFrom: " + text.substr(0,40) + "..."); //Util.Debug(">> clipboardPasteFrom: " + text.substr(0,40) + "...");

View File

@ -164,6 +164,8 @@ addMouseHandlers: function() {
$D("connectButton").onclick = UI.toggleConnectPanel; $D("connectButton").onclick = UI.toggleConnectPanel;
$D("disconnectButton").onclick = UI.disconnect; $D("disconnectButton").onclick = UI.disconnect;
$D("descriptionButton").onclick = UI.toggleConnectPanel; $D("descriptionButton").onclick = UI.toggleConnectPanel;
$D("ctrlLockCheckBox").onclick = UI.updateSoftKeyState;
$D("altLockCheckBox").onclick = UI.updateSoftKeyState;
$D("noVNC_clipboard_text").onfocus = UI.displayBlur; $D("noVNC_clipboard_text").onfocus = UI.displayBlur;
$D("noVNC_clipboard_text").onblur = UI.displayFocus; $D("noVNC_clipboard_text").onblur = UI.displayFocus;
@ -413,6 +415,10 @@ sendCtrlAltDel: function() {
UI.rfb.sendCtrlAltDel(); UI.rfb.sendCtrlAltDel();
}, },
updateSoftKeyState: function() {
UI.rfb.updateSoftKeyState(this.value, this.checked);
},
setMouseButton: function(num) { setMouseButton: function(num) {
var b, blist = [0, 1,2,4], button; var b, blist = [0, 1,2,4], button;
@ -508,11 +514,19 @@ updateVisualState: function() {
$D('clipboardButton').style.display = "inline"; $D('clipboardButton').style.display = "inline";
$D('showKeyboard').style.display = "inline"; $D('showKeyboard').style.display = "inline";
$D('sendCtrlAltDelButton').style.display = "inline"; $D('sendCtrlAltDelButton').style.display = "inline";
$D('ctrlLockCheckBox').style.display = "inline";
$D('altLockCheckBox').style.display = "inline";
$D('ctrlLockLabel').style.display = "inline";
$D('altLockLabel').style.display = "inline";
} else { } else {
UI.setMouseButton(); UI.setMouseButton();
$D('clipboardButton').style.display = "none"; $D('clipboardButton').style.display = "none";
$D('showKeyboard').style.display = "none"; $D('showKeyboard').style.display = "none";
$D('sendCtrlAltDelButton').style.display = "none"; $D('sendCtrlAltDelButton').style.display = "none";
$D('ctrlLockCheckBox').style.display = "none";
$D('altLockCheckBox').style.display = "none";
$D('ctrlLockLabel').style.display = "none";
$D('altLockLabel').style.display = "none";
} }
// State change disables viewport dragging. // State change disables viewport dragging.
// It is enabled (toggled) by direct click on the button // It is enabled (toggled) by direct click on the button

View File

@ -70,6 +70,12 @@
<!--noVNC Buttons--> <!--noVNC Buttons-->
<div class="noVNC-buttons-right"> <div class="noVNC-buttons-right">
<input type=checkbox value="ctrlKey"
id="ctrlLockCheckBox">
<label for="ctrlLockCheckBox" id="ctrlLockLabel">CtrlLock</label>
<input type=checkbox value="altKey"
id="altLockCheckBox">
<label for="altLockCheckBox" id="altLockLabel" >AltLock</label>
<input type="image" src="images/ctrlaltdel.png" <input type="image" src="images/ctrlaltdel.png"
id="sendCtrlAltDelButton" class="noVNC_status_button" id="sendCtrlAltDelButton" class="noVNC_status_button"
title="Send Ctrl-Alt-Del" /> title="Send Ctrl-Alt-Del" />

View File

@ -25,10 +25,20 @@
<div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;"> <div id="noVNC_status_bar" class="noVNC_status_bar" style="margin-top: 0px;">
<table border=0 width="100%"><tr> <table border=0 width="100%"><tr>
<td><div id="noVNC_status">Loading</div></td> <td><div id="noVNC_status">Loading</div></td>
<td width="1%"><div id="noVNC_buttons"> <td width="300pt"><div id="noVNC_buttons">
<span style="float: right">
<input type=button value="Send CtrlAltDel" <input type=button value="Send CtrlAltDel"
id="sendCtrlAltDelButton"> id="sendCtrlAltDelButton">
</div></td> </span>
<span style="float: right">
<input type=checkbox value="ctrlKey"
id="ctrlLockCheckBox">
<label for="ctrlLockCheckBox">CtrlLock</label>
<input type=checkbox value="altKey"
id="altLockCheckBox">
<label for="altLockCheckBox">AltLock</label>
</span>
</div></td>
</tr></table> </tr></table>
</div> </div>
<canvas id="noVNC_canvas" width="640px" height="20px"> <canvas id="noVNC_canvas" width="640px" height="20px">
@ -47,6 +57,11 @@
"keymap.js"]); "keymap.js"]);
var rfb; var rfb;
var buttons = [
{name: 'ctrlLockCheckBox', onclick: updateSoftKeyState},
{name: 'altLockCheckBox', onclick: updateSoftKeyState},
{name: 'sendCtrlAltDelButton', onclick: sendCtrlAltDel}
];
function passwordRequired(rfb) { function passwordRequired(rfb) {
var msg; var msg;
@ -66,11 +81,14 @@
rfb.sendCtrlAltDel(); rfb.sendCtrlAltDel();
return false; return false;
} }
function updateSoftKeyState() {
rfb.updateSoftKeyState(this.value, this.checked);
return true;
}
function updateState(rfb, state, oldstate, msg) { function updateState(rfb, state, oldstate, msg) {
var s, sb, cad, level; var s, sb, level;
s = $D('noVNC_status'); s = $D('noVNC_status');
sb = $D('noVNC_status_bar'); sb = $D('noVNC_status_bar');
cad = $D('sendCtrlAltDelButton');
switch (state) { switch (state) {
case 'failed': level = "error"; break; case 'failed': level = "error"; break;
case 'fatal': level = "error"; break; case 'fatal': level = "error"; break;
@ -80,8 +98,15 @@
default: level = "warn"; break; default: level = "warn"; break;
} }
if (state === "normal") { cad.disabled = false; } var i;
else { cad.disabled = true; } for (i = 0; i < buttons.length; i++) {
var elem = $D(buttons[i].name);
if (state === "normal") {
elem.disabled = false;
} else {
elem.disabled = true;
}
}
if (typeof(msg) !== 'undefined') { if (typeof(msg) !== 'undefined') {
sb.setAttribute("class", "noVNC_status_" + level); sb.setAttribute("class", "noVNC_status_" + level);
@ -90,10 +115,15 @@
} }
window.onscriptsload = function () { window.onscriptsload = function () {
var host, port, password, path, token; var host, port, password, path, token, i;
$D('sendCtrlAltDelButton').style.display = "inline"; for (i = 0; i < buttons.length; i++) {
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel; var button = buttons[i];
$D(button.name).style.display = "inline";
if (button.onclick) {
$D(button.name).onclick = button.onclick;
}
}
WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn')); WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
document.title = unescape(WebUtil.getQueryVar('title', 'noVNC')); document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));