Fixing the Ajaxterm shift key (and no login) problem
April 28th, 2010 by adminAjaxterm is a wonderful little program written by Antony Lesuisse to create an ssh terminal from a browser window. This is important to me because a local library allows *only* web surfing from public terminals, but not ssh. So, I use ajaxterm to act as a ssh server that I can access from http.
However, I could not login. After some playing around, I determined that it was because I had capital letters in my password. When I looked at the way ajaxterm interprets keystrokes, it turns out that it captures the pressing of the shift key as a separate keystroke (and interprets it as uparrow). It then interprets the capitalized letter correctly — i.e. shift+A counts as two keystrokes, “shift” and “shift+A”. Uparrow in my shell provides the previous historical shell command. Thus, if my last command was “ls” then instead of “A”, hitting shift+A gives me “lsA”.
So I went back and looked at the code for ajaxscript (thank God for open source), and found where this was done. I put in a little line that captures the shift key by itself and sets it to the null character. Now everything works fine. Here’s the code for Mandriva 2010.0. I assume the files are in a similar place in Ubuntu and other debian distros. In any case, file you need to look at is ajaxterm.js, and on my box it lives in /usr/share/ajaxterm.
If you open up /usr/share/ajaxterm/ajaxterm.js, you will see a function keypress(ev):
function keypress(ev) {
if (!ev) var ev=window.event;
//s="kp keyCode="+ev.keyCode+" which="+ev.which+" shiftKey="+ev.shiftKey+" ctrlKey="+ev.ctrlKey+" altKey="+ev.altKey;
//debug(s);
//return false;
//else { if (!ev.ctrlKey || ev.keyCode==17) { return; }
var kc;
(etc...)
Basically, it goes through and captures any control codes, and then interprets each. If you turn on the debug code that’s in there you will find that the shift key is ev.keyCode=16 and ev.which=16. Thus, after the code checks for control, alt, etc. you just need to add a little snippet that turns the key into a no-op if the keycode is 16. I did it here (my added code is in red):
(...long list of characters...)
else if (kc==123) k="[24~"; // F12
if (k.length) {
k=String.fromCharCode(27)+k;
}
}
} else {
if (ev.which==16) {
k="";
kc=0;
}
if (kc==8)
k=String.fromCharCode(127); // Backspace
else
k=String.fromCharCode(kc);
}
That seems to have fixed the problem.
Posted in Computer stuff | No Comments »