I need a built-in on screen numeric keypad in my Application. For various reasons I cannot use the TMS Software or other commercial component offerings. I\'m very happy with
I don't know how to create window with the frame which is unfocusable when you click it, so the following one is without border. And as Andreas mentioned, use TSpeedButtons.
type
TKeypadForm = class(TForm)
SpeedButton1: TSpeedButton;
procedure SpeedButton1Click(Sender: TObject);
private
procedure CreateParams(var Params: TCreateParams); override;
procedure WMMouseActivate(var Message: TWMMouseActivate); message WM_MOUSEACTIVATE;
end;
procedure TKeypadForm.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := WS_POPUP or WS_THICKFRAME;
end;
procedure TKeypadForm.WMMouseActivate(var Message: TWMMouseActivate);
begin
Message.Result := MA_NOACTIVATE;
end;
procedure TKeypadForm.SpeedButton1Click(Sender: TObject);
begin
PostMessage(GetFocus, WM_KEYDOWN, VK_NUMPAD1, MakeLong(0, MapVirtualKey(VK_NUMPAD1, 0)));
end;
And here's how to show the keypad window
procedure TForm18.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_RETURN: ShowWindow(KeypadForm.Handle, SW_SHOWNOACTIVATE);
VK_ESCAPE: ShowWindow(KeypadForm.Handle, SW_HIDE);
end;
end;