Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

onKeyUp/Down and TEXTAREA, routeEvent()

0 views
Skip to first unread message

Kalin Kojouahrov

unread,
Jun 26, 1999, 3:00:00 AM6/26/99
to
Hello all!

Some time ago I posted similar question, but got no reply :-(

I am trying to make a "keyboard driver" in JavaScript. In a few words,
I'd like in a TEXTAREA to have "B" printed when you press "A" key for
example. That is in connection to entring Cyrillic on some forms.

Here is a very simplified example code:

<HTML>
<SCRIPT LANGUAGE="JavaScript">

function oneKey(e) {
status=e.which; // look at your status line to
// see what was pressed
e.which=42; // fix it to "*"
routeEvent(e); // pass it down ?
return false; // ##############
}

document.captureEvents(Event.KEYDOWN);
document.onkeydown=oneKey;
</SCRIPT>

<BODY>

<FORM>
Enter here: <TEXTAREA></TEXTAREA>
</FORM>

</BODY></HTML>

Unfortunately it DOES NOT work as I expected. Nothing changes, except if
I type the "*" symbol to which I want to substitute the input it does
NOT get printed in this version of the code. Any idea why? I suppose the
either routeEvent() is not working or property "which" is not changing..

If you change the //######## line to return true, it is printed.

Again anybody with ideas? I found something in the FAQ at:
http://www.irt.org/script/690.htm
but it doesn't seem to work in NN4.6 :-(

Kalin.

--
WWW: http://www.thinrope.net/
SnailMail: Kalin Kojouharov
Hokkaido University,
060-0818 Sapporo-shi, JAPAN


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

Martin Honnen

unread,
Jun 26, 1999, 3:00:00 AM6/26/99
to
To change the
event.which
with nn you need to request

netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
I am able to change the property and get the change reported but the
textarea nevertheless shows the typed key:

function handleKeys (e) {
if (e.target.name == 'textAreaName') {

netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
e.which = 'A'.charCodeAt();
java.lang.System.out.println('handleKeys: ' +
String.fromCharCode(e.which));
}
return routeEvent(e);
}
window.captureEvents(Event.KEYPRESS);
window.onkeypress = handleKeys;


<TEXTAREA NAME="textAreaName" ROWS="5" COLS="20"
ONKEYPRESS="java.lang.System.out.println(event.type + ': ' +
String.fromCharCode(event.which)); return true;"
></TEXTAREA>

shows for example

handleKeys: A

keypress: A

in the java console but the textarea shows the pressed key.

Doesn't seem to work with nn unless someone comes up with some magic.

The onchange handler should work. The keypress not.


>
> Kalin.
>
> --
> WWW: http://www.thinrope.net/
> SnailMail: Kalin Kojouharov
> Hokkaido University,
> 060-0818 Sapporo-shi, JAPAN
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

--

Martin Honnen

http://www.sector27.de/martin.honnen/jsgoddies.html

Kalin Kojouahrov

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
Thanks, Martin!

I tired the enablePrivilage, but got error:
uncaught Java exception
netscape/security/ForbiddenTargetException ("User didn't
grant the UniversalBrowserWrite privilege.")

Any idea how to make it work?

Anyway, that's going to Java and I'd better write a Java applet for
that if I'm swithing to it. My idea was to do away just with JavaScript.
My general idea is really a keyboard driver, so I don't mind using some
other way (i.e. not TEXTAREA).

Anybody, any more ideas? No Java please. Just JavaScript/JScript.

Kalin.

--
WWW: http://www.thinrope.net/
SnailMail: Kalin Kojouharov
Hokkaido University,
060-0818 Sapporo-shi, JAPAN

In article <37751F90...@sector27.de>,

Martin Honnen

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
NN security concept is based on running the java vm so if you want to
request things with javascript which are ususally not allowed you need
these liveconnect calls.

Kalin Kojouahrov wrote:
>
> Thanks, Martin!
>
> I tired the enablePrivilage, but got error:
> uncaught Java exception
> netscape/security/ForbiddenTargetException ("User didn't
> grant the UniversalBrowserWrite privilege.")
>

A script/applet calling the netscape.security stuff needs to be signed
or run locally. So to test it run locally (file: url).


> Any idea how to make it work?
>
> Anyway, that's going to Java and I'd better write a Java applet for
> that if I'm swithing to it. My idea was to do away just with JavaScript.
> My general idea is really a keyboard driver, so I don't mind using some
> other way (i.e. not TEXTAREA).
>
> Anybody, any more ideas? No Java please. Just JavaScript/JScript.


For IE the following works

<INPUT TYPE="text" NAME="aField"
ONKEYPRESS="event.keyCode =
String.fromCharCode(event.keyCode).toUpperCase().charCodeAt(); return
true;"
>

Adapt that as needed e.g. test event.keyCode for the desired characters.

--

Martin Honnen

http://www.sector27.de/martin.honnen/jsgoddies.html

0 new messages