Delphi: VK_SPACE, right key

I'm a little confused. On: http://delphi.about.com/od/objectpascalide/l/blvkc.htm

it says the right key for "Space" is # 20. Tried this and it doesn't work. However, replacing it with # 32 seems to work:

procedure TForm14.cxTextEdit5KeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in [#8,#32, '0'..'9']) then begin
  ShowMessage('Only numbers !');
  Key := #0;
  end;
end;

      

So now I'm not sure if this will work on all Windows versions?

+3


source to share


2 answers


Yes. VK_SPACE

is defined as 0x20

(in hexadecimal notation C 20

value equal to 32

) in all versions of Windows, your link also contains hexadecimal values.

Edit



As David points out, the virtual key code VK_SPACE

is irrelevant in the context of an event handler OnKeyPress

. (The fact that it is defined using the ASCII value of the space character should be considered a match.)

You can just rely on what #32

is the correct notation for the space character (as well #$20

or just ' '

).

+8


source


It says that the right key for Space is # 20.

No no. #20

- a character with a sequential number of 20 decimal places. The table you are referring to contains hex values. VK_SPACE

is a virtual key code, an integer whose value is 32 decimal, 20 hexadecimal.



However, the virtual key codes are not used by the event handler OnKeyPress

and the meaning is VK_SPACE

simply not relevant to your question. The event handler OnKeyPress

uses UTF-16 character codes. UTF-16 character code for space 32 decimal, 20 hex. If you are using pre-Unicode Delphi OnKeyPress

uses ANSI instead of UTF-16.

Remember that it OnKeyPress

uses UTF-16 / ANSI codes because it matches WM_CHAR

. Both OnKeyDown

and OnKeyUp

use the virtual key codes by running them from WM_KEYDOWN

and WM_KEYUP

.

+4


source







All Articles