![]() |
|
#1
|
|||
|
|||
|
Hey everyone I need a function that converts a Win32 virtual-key code to a Delphi Char.
Thanx in advance! Moti Zilberman |
|
#2
|
|||
|
|||
|
If you want to catch chars in KeyDown or KeyUp
procedures you can try this: Key type is Word and convert into char is Char(Key). In that case instead of VK codes you will get capital letter of pressed key. I`m using this method. So, if you pressing "k" in procedure KeyDown you`ll get Char(key)="K" and so on. For letters you `ll get itselves... Any questions send to v_matroskin@aport2000.ru |
|
#3
|
|||
|
|||
|
Pretty simple since VK code are just the numeric representation of the character... simply put into code...
var ch: Char; begin ch := Chr(Key); // "Key" being the var with the VK code // check if the key is a regular character rather than // a special key like up, down, ect // if not in the normal character range change it to null if not(ch in [' '..'~'] then ch:=#0; // make sure in your code to test if ch = #0 and skip it end; DelphiFan |
|
#4
|
|||
|
|||
|
Hi Moti!
If you only want to handle standard keys, you can go the way shown by VVM and DelphiFan. If you want to get any char on your keyboard just by looking on the VK_codes, well, thats another problem... There are: - Key codes that are no keys : VK_LBUTTON, VK_RBUTTON ... - Key codes that don't represent a char: VK_HOME, VK_UP ... - chars that don't have an own key code : !"з$%&/... - chars that are produced by more than one keystrike : рст You have to filter out any invalid key codes, check previous pressed key codes for modifiers (VK_SHIFT, VK_MENU) and double key characters ('`','^', the key codes are OEM specific) and keep in mind the Caps Lock state (VK_CAPS). Thats a keyboards drivers task - but if you want to do it... :-) HTH )Verence |
![]() |
| Thread Tools | |
| Display Modes | |
|
|