?
Solved

keyPress method & keyPress ASCII codes???

Posted on 2003-03-11
12
Medium Priority
?
3,934 Views
Last Modified: 2008-07-04
Hello,
I was just wondering if there is something like a 'keypress method.' For example, you can do
document.formname.buttonname.click()
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 -^.^-
0
Comment
Question by:lil_puffball
[X]
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
12 Comments
 
LVL 10

Expert Comment

by:kollegov
ID: 8116995
document.formname.textbox.value+=String.fromCharCode(100)

You can put several chars at once
String.fromCharCode(code1,code2,.......)
0
 
LVL 10

Expert Comment

by:kollegov
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
http://www.unicode.org/charts/

Or for simple cases just use:
<html>
<body>
Press key to see it's code
</body>
<script>

function onpress() {
  alert(event.keyCode)
}
document.body.onkeyup=onpress
</script>
</html>
0
 
LVL 12

Author Comment

by:lil_puffball
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...
0
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

by:
kollegov earned 320 total points
ID: 8124990
As for codes check this document
http://www.unicode.org/charts/PDF/U0000.pdf
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

<script>
var last_range;
function remember() {
   if(document.selection) {
     if(document.selection.createRange) {
       last_range = document.selection.createRange();  
     }
  }
}

function insert(code) {
  if(last_range) {
    s=String.fromCharCode(code);
    last_range.text=s;
  }
}
</script>

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

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

Author Comment

by:lil_puffball
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!
0
 
LVL 12

Author Comment

by:lil_puffball
ID: 8148883
kollegov,
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...
0
 
LVL 16

Expert Comment

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

Expert Comment

by:kollegov
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 ...
http://www.unicode.org/charts/
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
processing.
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
 












0
 
LVL 16

Expert Comment

by:sh0e
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)
http://home.shafe.com/~mikes/charcode.html

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
0
 
LVL 16

Expert Comment

by:sh0e
ID: 8157011
http://developer.irt.org/script/684.htm
details the use of unicode sequences
0
 
LVL 10

Expert Comment

by:kollegov
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.

Max
0
 
LVL 12

Author Comment

by:lil_puffball
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! :)
0

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