Mirror

Detect whether the default or the keypad Enter key was pressed (Views: 300)


Problem/Question/Abstract:

How to detect whether the default or the keypad Enter key was pressed

Answer:

You could put something like this on an Application.OnMessage event, or trap the WM_KEYUP message in your component:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := HandleMessage;
end;

procedure TForm1.HandleMessage(var Msg: TMsg; var Handled: Boolean);
begin
  Handled := False;
  if Msg.Message = WM_KEYUP then
  begin
    if Msg.wParam = VK_RETURN then
    begin
      if Msg.LParam and (1 shl 24) > 0 then
        ListBox1.Items.Add('Keypad Return pressed')
      else
        ListBox1.Items.Add('Regular Return pressed')
    end;
  end;
end;

<< Back to main page