LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2003, 11:52 AM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
convert a character in a box to keycode number


convert a character in a box to keycode number
What is the function that allowed you to convert a text character in a text box to keyCode ?

The code below illustrate how to do it when a user press a key on a keyboard.
===================================

Code:
function show_key_value()
 {
   alert(event.keyCode)
 }

<INPUT type="text" id="Keyboard" maxlength=4 onkeyup='show_key_value()'>
 
Old 10-14-2003, 12:41 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Sorry - am I missing something - you have just given the function.
 
Old 10-14-2003, 01:15 PM   #3
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
reply

Hi David_Ross

the event.keyCode function return a 65 for a character 'a'
the myString.charCodeAt(0) function return a 97 for a
character 'a'

What I was looking for is a function similar to that of charCodeAt but will return the same numberic value as that of the function event.keyCode

=====================================
Code:
function convert_to_keycode() 
{ 
myString = input_key.value 
alert(myString.charCodeAt(0)) 
} 


function show_key_value() 
{ 
alert(event.keyCode) 
} 

<LABEL for="Event Key Code Number" tabindex="3">Alphanumeric input:</LABEL> 
<INPUT type="text" name="input_key" maxlength=16 onkeyup='validate_alphanumeric_input(input_key)'> 
      
<INPUT type="button" value="convert a value to key code" onclick="convert_to_keycode(input_key)"> 
<BR> 

<BR> 
<LABEL for="Event Key Code Number" tabindex="3">Keyboard input:</LABEL> 
      
<INPUT type="text" id="Keyboard" maxlength=4 onkeyup='show_key_value()'>

Report this post to a moderator
 
Old 10-14-2003, 04:14 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I assume you mean you want to get the keycode needed for generating a specific character within a string? I don't think it would be possible without remembering what keys were pressed to acheive that character. Considering that you can generate "A" with usng shift and a or Caps and a.

I hope that makes sense.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
changing character set in linux box haora Linux - Newbie 1 06-20-2005 10:37 AM
kernel cannot convert a name into device number dreambrother Linux - Newbie 4 05-31-2005 05:51 PM
How do I add character+number to get char in C++? needforspeed Programming 10 02-10-2004 12:16 AM
Can 't convert from a character to octal value in memory Linh Programming 2 07-21-2003 03:11 PM
Using sed to convert a string to a character? whansard Linux - General 2 01-10-2003 05:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration