msd 5 Posted December 28, 2022 Hello, On the form OnFormKey UP or DWN, we can use the entire keyboard, but for the numeric part, we have VK_ADD, VK_MULTIPLY,... I need some advice for using those keys in OnFormKeyDown, Up, or Press like this sample below: When a user searches for data in the TEdit VCL by typing letters and numbers and then clicking on the numeric + key VK_ADD, the app does something BUT WITHOUT adding +char to the TEdit VCL control. Simple: I need to use those keys but without the characters they represent: +, -, /, and *. Thanks for the advice in advance... Share this post Link to post
Mark- 29 Posted December 28, 2022 SWAG would be to capture the key in OnKeyDown test for the key if a VK_ADD, set the KeyDown(var Key: Word; to 0 and add the + to the edit field. Same for the other -/etc. keys. And you might need to turn on KeyPreview for the form. 1 Share this post Link to post
PeterBelow 239 Posted December 28, 2022 (edited) 14 hours ago, msd said: Hello, On the form OnFormKey UP or DWN, we can use the entire keyboard, but for the numeric part, we have VK_ADD, VK_MULTIPLY,... I need some advice for using those keys in OnFormKeyDown, Up, or Press like this sample below: When a user searches for data in the TEdit VCL by typing letters and numbers and then clicking on the numeric + key VK_ADD, the app does something BUT WITHOUT adding +char to the TEdit VCL control. Simple: I need to use those keys but without the characters they represent: +, -, /, and *. Thanks for the advice in advance... Use the OnKeyPress event of the edit control. Like this: procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key = '+') and (GetKeyState(VK_ADD) < 0) then begin Key := #0; label1.Caption := 'VK_ADD'; end else label1.Caption := string.Empty; end; The GetKeyState API function allows you to check which key is currently down. The code above will let the '+' key of the normal keyboard add the character to the edit but block the numpad plus key input. Edited December 28, 2022 by PeterBelow 1 Share this post Link to post
programmerdelphi2k 237 Posted December 28, 2022 (edited) {$R *.dfm} procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key in [VK_ADD, VK_MULTIPLY { ,...] } ]) then begin Key := 0; Memo1.Lines.Add('OnKeyDown: VK_ADD, VK_MULTIPLY, ... pressed'); end; end; procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if CharInSet(Key, ['+', '-', '/', '*']) then begin Key := #0; Memo1.Lines.Add('OnKeyPress: VK_ADD, VK_.... pressed'); end; end; end. Edited December 28, 2022 by programmerdelphi2k 1 Share this post Link to post