Главная страница | назад





Article #17807: Sending keystroke #255 to a windows control.

 Question and Answer Database
FAQ2807D.txt Sending keystroke #255 to a windows control.
Category :VCL
Platform :All
Product :All 32 bit
Question:
Since the keybd_event() function only accepts key values
up to 254, how can I send the keystroke #255 to a
Windows control?
Answer:
This can be very useful for entering a value in an edit control
for a foreign, symbol, or wingding character. The following
example shows how to stuff the keyboard with the #255
character and direct it to any Window control. Note: This
method should not be used to enter characters that could
normally be processed by the keybd_event() function.
procedure TForm1.Button1Click(Sender: TObject);
var
KeyData : packed record
RepeatCount : word;
ScanCode : byte;
Bits : byte;
end;
begin
{Let the button repaint}
Application.ProcessMessages;
{Set the focus to the window}
Edit1.SetFocus;
{Send a right so the char is added to the end of the line}
SimulateKeyStroke(VK_RIGHT, 0);
{Let the app get the message}
Application.ProcessMessages;
FillChar(KeyData, sizeof(KeyData), #0);
KeyData.ScanCode := 255;
KeyData.RepeatCount := 1;
SendMessage(Edit1.Handle, WM_KEYDOWN, 255,
LongInt(KeyData));
KeyData.Bits := KeyData.Bits or (1 shl 30);
KeyData.Bits := KeyData.Bits or (1 shl 31);
SendMessage(Edit1.Handle, WM_KEYUP, 255,
LongInt(KeyData));
KeyData.Bits := KeyData.Bits and not (1 shl 30);
KeyData.Bits := KeyData.Bits and not (1 shl 31);
SendMessage(Edit1.Handle, WM_CHAR, 255,
LongInt(KeyData));
Application.ProcessMessages;
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99