I am having local networking and internet connection issues with
ftp access to my web site for the moment. Hopefully I will get that
solved soon. When I do, I can post the current state of the application.
It is a calculator app with some features that I have not seen in calculator
apps.
I can post the source code file containing the keyboard event handling
code. How would I include a plain text code source file here?
In breif: all the keyboard event handlers begin with
var registerKeyPress = function(event)
{
var e = event || window.event
keyNum = e.keyCoce || e.charCode || event.which
keyNum = keyNum.toString()
switch(keyNum)
{
// … etc …
}
}
var registerKeyDown = function(event)
{
var e = event || window.event
keyNum = e.keyCoce || e.charCode || event.which
keyNum = keyNum.toString()
switch(keyNum)
{
// … etc …
}
}
var registerKeyUp = function(event)
{
var e = event || window.event
keyNum = e.keyCoce || e.charCode || event.which
keyNum = keyNum.toString()
switch(keyNum)
{
// … etc …
}
}
The keypress handler is for executing code according to the
key pressed
The kedown and keyup handlers are for swapping img source
values for key pad images.
I think I see a reason for the problem I am having, as I compose this…
the variable keyNum is defined in the broader scope and not in the
local scope of the handler, so may be acting as a static variable somehow.
These function are defined inside of a constructor function. Also inside
the constructor function is defined keyNum, but outside of the event
handling functions.
The “SP” key is for space so space can be entered into input string.
“use key pad” is to activate keyboard event processing in addition to
mouse click, over and out to enter characters.
Further investigation: I tried the snippet of code offered* and what I am getting are literal characters
not character codes.
*
document.body.addEventListener(“keydown”, keyPressed, false);
function keyPressed(e) {
console.log(e.keyCode);
}
As far as older browsers returning different codes for keyCode and charCode, that is what I was
allowing for in the original application code.
I have the app in its current state: far from complete, but up enough to demonstrate
http://www.jekillen.com/dev/web_calculator