Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Q: TWMKEY -> char

46 views
Skip to first unread message

EnviTech AS

unread,
Jan 17, 2001, 7:17:50 AM1/17/01
to
How do I convert a TWMKey message to characters with upper/lower case and
ignore shit, ctrl, alt etc, so I get the same result as OnKeyPress(Key:
Char)

Thanks!


János Schmidt

unread,
Jan 17, 2001, 7:55:12 AM1/17/01
to
Use the function "Chr(Message.CharCode)", where Message is of type
TWMKey, and check the result by the virtual keycode list. > There are
unfortunately only the VK_XXXX for the non-alpha keys defined, but these
last ones you can define yourself (see Windows.pas) using the ASCII
char-set.

Regards
-János

Peter Below (TeamB)

unread,
Jan 21, 2001, 12:07:30 PM1/21/01
to

Ideally you should do any processing that needs this information in
OnKeyPress, not in response to a WM_KEYDOWN message.

{: Obtain the character that will result from the virtual key
passed in.
@param vkey is the virtual key code, e.g. Key parameter of an
OnKeyDown handler.
@returns the character or '' if the key does not result in a
character. On rare occasions the function may return two
characters, e.g. if an accent key is pressed followed by
another character that does not have an accented version. }
Function GetCharFromVKey( vkey: word ): String;
var
keystate: TKeyboardState;
retcode: Integer;
begin
Win32Check( GetKeyboardState( keystate ));
SetLength( Result, 2 );
retcode := ToAscii( vkey,
MapVirtualKey( vkey, 0 ),
keystate,
@Result[1],
0 );
Case retcode Of
0: Result := ''; // no character
1: SetLength(Result,1);
2: ;
Else
Result := ''; // retcode < 0 indicates a dead key
End;
end;

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: Till Feb.2001 i will only visit the groups on weekends, so be
patient if i don't reply immediately.

0 new messages