keyPress method & keyPress ASCII codes???

Posted on 2003-03-11
Medium Priority
Last Modified: 2008-07-04
I was just wondering if there is something like a 'keypress method.' For example, you can do
to automatically get the effects of clicking a button or whatever. Is there something else, for example
document.formname.textbox.keyPress(100) to automatically enter a letter into a textbox?

In fact, it would be even better if someone could provide a comprehensive website that lists some common methods.

Also, does anyone know of a good site that lists all the keypress ASCII codes? I've been searching on Google to no avail.

I will increase the points if anyone has a very good answer.

Thanks in advance,
L'il Puffball -^.^-
Question by:lil_puffball
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
LVL 10

Expert Comment

ID: 8116995

You can put several chars at once
LVL 10

Expert Comment

ID: 8117026
Some more info
String.fromCharCode(code1, code2, ..., coden)
The code argument is the series of Unicode character values to convert into a string.

So you can get UNICODE tables for any language

Or for simple cases just use:
Press key to see it's code

function onpress() {
LVL 12

Author Comment

ID: 8122443
Thank you, kollegov.
However, I would prefer if the code could actually press a key rather than adding it to the end of the textbox--for example, what if the cursor were in the middle of the textbox? The letter would be added to the end rather than where the cursor is. Also, I'm not sure I quite get the website you directed me to...
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 10

Accepted Solution

kollegov earned 320 total points
ID: 8124990
As for codes check this document
Scroll down to characters table, codes for characters (HEX) listed below each char

As for inserting the main problem is loosing focus when you press any button or link outside
With MIE this can be done, but not with NN

var last_range;
function remember() {
   if(document.selection) {
     if(document.selection.createRange) {
       last_range = document.selection.createRange();  

function insert(code) {
  if(last_range) {

<form name="a">
  <input type="text" name="t" value="11111111" onchange="remember();" onFocus="remember();">
  <input type="button" onClick="insert(100);" > 

Put cursor on any position of input string and press button
LVL 12

Author Comment

ID: 8139524
Thanks again, kollegov.
I'm quite busy at this moment, so it might take me awhile to get through this but looks good!
LVL 12

Author Comment

ID: 8148883
Sorry for the delay. Anyways, that's fantastic! It's not quite what I was looking for but an excellent alternative.

I'm increasing the points to 75, but 75 only because the second part of my question wasn't answered very well. The last page you directed me to did contain ASCII codes but was not complete. What I would like is something like the following:

1: key
2: key
100: d

So basically complete from 1 to ???

If you know of a site I will increase points to 150.

Also, is there really no keypress method? For example, if there was a keypress method I could have a button that when the user clicks, f1 could be executed and the help thing would come up. Not that I'm thinking of doing that--the current code is great for my purposes, but just curious...
LVL 16

Expert Comment

ID: 8156674
full table with an inventive name :p
totally are 256 in the charset..
for reasons of some limitations that i wont go into :D
LVL 10

Expert Comment

ID: 8156921
First of all Javascript use NOT ASCII   but    UNICODE  
Unicode is contains characters from ALL WORLD ALPHABETS unlike ASCII is american only
Check other pages listed on link I gave you first time ...
The second link http://www.unicode.org/charts/PDF/U0000.pdf is Just Latin-1 subset
of unicode characters...

ASCII codes is just first 256 unicode chars which fit in 2 alphabets
Latin-1 and Latin-Extended-A(B)  last depends on system

JS use FULL unicode but not just ASCII  
Unicode is 16 bit coding
ASCII is only 8 bit  and it's only 256 of first unicode chars

The next:
F1 is functional KEY  you can't intercept it as any other hotkeys used to control browser behaviour.
Browser first handle input events itself and then MAY (or may NOT) pass event to javascript engine.
With F1 it do not pass it to script.
You can post event (or fake post) to javascript, but this wouldn't involve browser for input events
What's you are asking for (actually post event to browser) is disabled due to security reasons.
When JS will be able to post events to BROWSER then JS will have unlimited access to your filesystem
Would this hole exsists, why not to record sequence of key and mouse events
necessary to open you windows password file in browser and then email it to me ? Hehe :)
Why not to

There is no problems to fake events inside JS, but this events do not go out to browser

LVL 16

Expert Comment

ID: 8157006
i think the site youve given puff is too complex.. which is why shes havin trouble with it..
heres a site that might be easier to reference as it is in base 10 and actually implemented in javascript (view the source)

btw if you want to use the hex values you must use \u####
# representing the digits of the number..

btw youre claim that ascii is not used is kind of wrong..
and support for unicode specifications were supported in an update with the ecmascript standard..
unicode wasnt fully supported until nn4+ and around ie4+
and unicode itself can be seen as somewhat of an extension on the ascii standard
LVL 16

Expert Comment

ID: 8157011
details the use of unicode sequences
LVL 10

Expert Comment

ID: 8157148
Here is LIST of some control KEYs in ASCII set
http://www.cs.tut.fi/~jkorpela/chars/c0.html    ( c0 - control characters standard )

The rest are just printable chars and you may use it's codes like 'A'
and I guess you actually do not need to know it's codes when you can use this :)

Well, I think the most confusion goes out of some missunderstanding
First of all KEYBOARD :
It have 'normal' characters and some special characters
Normal chars are sent as-is and scpecial are
coded with escape sequence like F1 =ESC,59  (e.g 2 bytes)
(you can find more IBM PC scancodes at http://www.jimprice.com/jim-asc.htm)
Second is programm (BROWSER)
When browser parse user input events it interpret control characters
and then put printables in sting ( let's imagine text field input )  converting it by the way
from scancode to unicodes (dependeng on currently selected language/locale )

There is  thing  you need to understand  
You can put control sequence in string, but why you think browser should interpret this string same as
keyboard input ?! No it wouldn't...It interpret only user input (keyboard and mouse events)
In best case control chars you put in string will show up as some 'hierogliphs' in your string :)
The second as I told you have no ability to post input events to browser programmaticaly from Javascript.
(Just a simple security protection )

When from the begining you'd told us in more details what you are  trying to do
( I can guess you are trying to fake pressing of browser control characters like F1 or Ctrl+B or whatever else )
Then this thread can be much shorter.

LVL 12

Author Comment

ID: 8162220
Well, anyways, thx both of you...I've found a partial answer somewhere else, so it's ok. Thanks again kollegov and sh0e as well...this isn't the first time you've helped me out! :)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question