By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,472 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,472 IT Pros & Developers. It's quick & easy.

onKeyPress in Opera 7.11

P: n/a

I have included a file below that tests onKeyPress in Opera 7.11. I am
getting peculiar behavior. When the file is first loaded, pressing the
keypad + causes the textarea to get physically larger on the screen, and
pressing the keypad - causes the textarea to get physically smaller. I
click on the scrollbar then this behaviour stops and subsequent
keystrokes are displayed appropriately. Is this some kind of bug in
Opera 7.11?

================================================== ==========
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 strict//EN">
<html>
<head>
<title>Title</title>
<script type="text/javascript">

var transcriptContents = "";
var lineCnt = 0;

function tprint(_line) {
transcriptContents += lineCnt++ + " "+ _line + "\n";
transcript.value = transcriptContents;
};

function Initialize() {
transcript = document.getElementById("transcriptId");
tprint("Ready...");
};

function OnKeyPress() {
var code;
var codeStr;
var charStr;
code = event.keyCode ?
event.keyCode :
event.charCode ?
event.charCode :
event.which;
codeStr = code.toString();
charStr = Code2Str(code);
tprint(" code:" + codeStr + " char:" + charStr);
return false;
};

function Code2Str(code) {
switch(code) {
case 57357:return '<Home>';break;
case 57358:return '<End>';break;
case 57359:return '<PageUp>';break;
case 57360:return '<PageDown>';break;
case 57361:return '<UpArrow>';break;
case 57362:return '<DownArrow>';break;
case 57363:return '<LeftArrow>';break;
case 57364:return '<RightArrow>';break;
case 57370:return '<Insert>';break;
case 57371:return '<Delete>';break;
case 57376:return '<Alt>';break;
case 57377:return '<Shift>';break;
case 57378:return '<Ctrl>';break;
case 8:return '<Backspace>';break;
case 9:return '<Tab>';break;
case 10:return '<Shift-Tab>';break;
case 13:return '<Enter>';break;
default:return String.fromCharCode(code);
};
};

</script>
</head>
<body onLoad="Initialize()" onKeyPress="OnKeyPress()">
<p>Transcript</p>
<textarea name='transcript'
id='transcriptId'
size=50
wrap="soft"
readonly
rows=22 cols=30 >
</textarea>
</body>
</html>
--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a


Albert Wagner wrote:
I have included a file below that tests onKeyPress in Opera 7.11. I am
getting peculiar behavior. When the file is first loaded, pressing the
keypad + causes the textarea to get physically larger on the screen, and
pressing the keypad - causes the textarea to get physically smaller. I
click on the scrollbar then this behaviour stops and subsequent
keystrokes are displayed appropriately. Is this some kind of bug in
Opera 7.11?


If you look at the View->Zoom menu of Opera 7 then you will find that
+/- are indeed mapped to zoom in/out by 10%

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
On Sun, 28 Sep 2003 13:44:01 +0200
Martin Honnen <Ma***********@t-online.de> wrote:


Albert Wagner wrote:
I have included a file below that tests onKeyPress in Opera 7.11. I
am getting peculiar behavior. When the file is first loaded,
pressing the keypad + causes the textarea to get physically larger
on the screen, and pressing the keypad - causes the textarea to get
physically smaller. I click on the scrollbar then this behaviour
stops and subsequent keystrokes are displayed appropriately. Is
this some kind of bug in Opera 7.11?


If you look at the View->Zoom menu of Opera 7 then you will find that
+/- are indeed mapped to zoom in/out by 10%

<snip>

I suspected as much, but I am trapping all keyboard input and not
passing it through. The code traps +/- from the main keyboard but +/-
from the keypad on the right get through, UNTIL the textarea scroll bar
is clicked; then they too are successfully trapped. So, I assume that
you are saying that: "yes, it's a bug in Opera 7.11."
--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #3

P: n/a
Albert Wagner <al******@tcac.net> writes:
I suspected as much, but I am trapping all keyboard input and not
passing it through. The code traps +/- from the main keyboard but +/-
from the keypad on the right get through, UNTIL the textarea scroll bar
is clicked; then they too are successfully trapped. So, I assume that
you are saying that: "yes, it's a bug in Opera 7.11."


Actually, clicking anywhere in the text area (giving it focus)
prevents the zooming from working.

Not a bug. It is expected behavior. In Opera, the numeric keyboard
keys "+" and "-" have a default behavior, and you do nothing to
suppress it.

If you call the W3C Events DOM method "event.preventDefault()", then
the problem goes away.

Another solution is to change the call to the function to
onKeyPress="return OnKeyPress(event)"
so you further return the false that OnKeyPress returns. This also
prevents the default behavior.

Btw, your code is based on using a global event variable, which is a
bad idea that comes from IE. You should pass the event as an argument
to the handler function. Then it works in Mozilla too.

Also notice that Opera has changed the keyCodes in O7.20, so that it
matches IE and Mozilla, so some of the codes might need to be changed.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
On 28 Sep 2003 17:42:51 +0200
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote:

<snip>
Thank you, Lasse. When I post, I always hope that you reply. I always
get more than just an answer to a question; I also get the why and how
to improve it. Thanks again.

--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #5

P: n/a
On 28 Sep 2003 17:42:51 +0200
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote:
<snip>
Also notice that Opera has changed the keyCodes in O7.20, so that it
matches IE and Mozilla, so some of the codes might need to be changed.


I was wondering about those. What keycodes am I looking at from 7.11?

--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.