Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3944
  • Last Modified:

keyPress method & keyPress ASCII codes???

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
lil_puffball
Asked:
lil_puffball
  • 5
  • 4
  • 3
1 Solution
 
kollegovCommented:
document.formname.textbox.value+=String.fromCharCode(100)

You can put several chars at once
String.fromCharCode(code1,code2,.......)
0
 
kollegovCommented:
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
 
lil_puffballAuthor Commented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
kollegovCommented:
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
 
lil_puffballAuthor Commented:
Thanks again, kollegov.
I'm quite busy at this moment, so it might take me awhile to get through this but looks good!
0
 
lil_puffballAuthor Commented:
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
 
sh0eCommented:
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
 
kollegovCommented:
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
 
sh0eCommented:
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
 
sh0eCommented:
http://developer.irt.org/script/684.htm
details the use of unicode sequences
0
 
kollegovCommented:
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
 
lil_puffballAuthor Commented:
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

Independent Software Vendors: 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!

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now