On Tue, 28 Feb 2006 13:37:46 +0200, Vahan Yoghoudjian wrote:
>I know how to convert from lowercase to uppercase characters
>
>ord(Key) - ord('a') + ord('A') will return the lowercase of the pressed key
>// after making sure that Key is a lowercase character of course
>
>is there any relation where I can return the upper value of the numerical
>keys.
>
>For example: if key 2 is pressed, I want to return @, if key 4 is pressed I
>want to return $, etc...
>
>Thanks in advance
Vahan,
Are you sure you want to do this? Shifted alphabetic characters are fixed.
Shifted numbers are not.
1) The numeric keypad might be used
2) Shifted numbers do not always return the same character on differing
keyboards (eg a shifted 2 on my keyboard is a " character and shifted 3 is a £
character.
Making assumptions about what keyboard anyone is using can cause a lot of
confusion.
If you must the easiest way would be to have a lookup table with one string of
input values and one for output values (it might make sense to allow for non US
keyboards by having one output string for each keyboard). Use the pos function
to find out where in the input string the character is then take the
corresponding character form the output string.
BTW
1) Delphi has constants for Right and Left Shift Locked. It might be possible to
effectively apply a shift lock to the keyboard making the translation
unnecessary.
2) The following might be of use for changing the case of letters.
Ord (Key) XOR (Ord ('a') XOR Ord ('A'))
Not only will it flip the case of letters ('A' becomes 'a' and vice
versa)
but it should be faster than your subtraction.
To return the lower case character (both 'a' and 'A' become 'a') use
Ord (Key) OR (Ord ('a') XOR Ord ('A')) { Note OR for XOR }
To return the upper case character (both 'a' and 'A' become 'A') use
Ord (Key) OR NOT (Ord ('a') XOR Ord ('A')) { Note OR for XOR }
Generally speaking bitwise operations (such as XOR) are faster than
arithmetic.
--
Regards,
Allan JM Smith
(Northwood, Middlesex, England)
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/