Javid
Javid

Reputation: 39

My delphi application is incompatible with native keyboards. What should I do?

My delphi application is incompatible with native keyboards. What should I do? To explain more, first look at these pictures:

Here's an image of what an Italian keyboard looks like: http://en.wikipedia.org/wiki/Keyboard_layout#Italian

You can find the normal one (United States keyboard) in the same page.

If we press the Shift+2 (or any Shift+Number) with the normal keyboard a @ must be written but if we do it with the Italian keyboard a " must be written. But in my application, with both keyboards, it treats every keyboard as a normal keyboard! for example when I press Shift+2 within the Italian keyboard, it types @ instead of "

I'm using Delphi 7. You can test my app here: en.apadanasoftware.com/forums

Thnx in advance

Upvotes: 1

Views: 361

Answers (3)

Cosmin Prund
Cosmin Prund

Reputation: 25678

First of all I'm almost offended, why would you think the Unitated States Keyboard is the "normal" one? It doesn't have ANY of the accented letters that I need to use every day! Joke aside (and yeah, typing this on my US format keyboard), what you're asking is wrong and irrelevant. Here's why:

  • The text printed on the buttons on the keyboard bares little resemblance to what happens when the user presses the button. The keyboards generates a "scan code" that's interpreted by Windows according to the selected keyboard format. I can hit LeftALT+SHIFT to rotate the keyboard format from US to Romanian on my computer. On my home computer there's also French in the rotation. Sure, I don't have any of the accented letters on my US keyboard (as in printed text on the buttons), but rest assured, it's totally irrelevant since I don't look at the keys while typing any way :)
  • The fact that the " character is not on the same button 2 shouldn't concern you. It's the final users choice, and the final users knows exactly what key to press to get whatever symbol. You wound not be doing him a service by interpreting the Shift+"2" as a " just because that's what it means on the US keyboard! He would ask why is he typing the " and getting a [ on your application?

What I'm trying to say is that your application can't possibly be incompatible with native keyboards. It works just fine, you just don't know what buttons to press - but the end user knows, since he owns both the computer and the keyboard.

Upvotes: 0

A.Bouchez
A.Bouchez

Reputation: 411

Where do you receive the keyboard event in your application?

If you use a OnKeyPress event, like

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);

you will receive the key as '@': i.e. the conversion is done by Windows.

If you use a OnKeyDown event, like

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

you'll receive the virtual key code, i.e. the raw key code, and you'll have to convert it using the Shift value.

See http://msdn.microsoft.com/en-us/library/dd375731(VS.85).aspx about virtual keys.

I guess you used OnKeyDown instead of OnKeyPress in your application.

Upvotes: 0

Re0sless
Re0sless

Reputation: 10886

The characters that are sent to your Delphi application are controlled by Windows, not Delphi, the only possible exception to this is if you are intercepting the windows messages and preforming custom key handling.

If you are connecting both keyboards to the same PC, this may be caused by windows having the wrong keyboard layout loaded.

In Windows Go to "Control Panel/ Regional and Language Options" then under the Languages tab, press the Details button in the "Text services and input languages" group box, there you should be able to see what keyboard layouts you have loaded and load in new ones, if needed.

How to change your keyboard layout from Microsoft

Upvotes: 5

Related Questions