• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

Handling OEM characters in KeyDown?

I need an editbox which
* has a canvas to display background image
* limited to accept a certain range of keystrokes
* prevent user from selecting its content by mouse

I descended my component from TCustomContol and captured KeyDown method:

procedure TMMEdit.KeyDown(var Key: Word; Shift: TShiftState);
   if (Key = VK_Back) then begin

      if (length(fText)>0) then Delete( fText, Length(fText), 1);
      fText:= fText+ Char( key );


My main problem is that fText:= fText+ Char( key ); doesn't work correctly for special characters like á, é, Õ, Ö.
How can I handle these OEM characters correctly?

1 Solution
hello Levente , the WM_KeyDown message is before the Keystroke is Translated to the correct Character, if you want the actual Charaters then use the WM_CHAR message. . . which is the OnKeyPress, otherwize you'll maybe need to use the ToASCII
LeventeAuthor Commented:
I should've takne closer look into Windows' messages. Thanks

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now