Forum > LCL

Using KeyPress event, how to get subsequent key presses?

(1/2) > >>

new2thisagain395:
In a TMemo, during the KeyPressed event how do you get the key pressed to be "disposed of" (or dropped is maybe a better term) once you do what you want with it, so that the next keystroke can be captured?  I'm using this event code:


--- Code: ---procedure TSCU.Memo1KeyPress(Sender: TObject; var Key: char);
var
  DateString: string;
  TimeString: string;
  InReadPW:   boolean = false;
  R:          Longint;

begin
     KeyPressed := UpCase(Key);
                                             

--- End code ---
and while it reads the first key pressed, subsequent key presses leave KeyPressed stuck at the first character that was typed (viewing in the Watch window while debugging).  Once I grab that key (I am adding it to a buffer) how do I get the next key pressed to be captured by this function?

jamie:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TSCU.Memo1KeyPress(Sender: TObject; var Key: char);var  DateString: string;  TimeString: string;  InReadPW:   boolean = false;  R:          Longint; begin     KeyPressed := UpCase(Key);                                              
You don't stay in this event, you allow it to exit, the next key you press will trigger this event again.
you need to use an external buffer to this event.

Joanna:
Would it be better to use keydown event instead for this?

Zvoni:

--- Quote from: Joanna on March 28, 2024, 03:07:47 am ---Would it be better to use keydown event instead for this?

--- End quote ---
rather KeyUp
KeyDown fires permanently, when you hold a key down.
KeyUp only fires once per "Key-Press"

alpine:

--- Quote from: new2thisagain395 on March 28, 2024, 01:14:34 am ---*snip*
and while it reads the first key pressed, subsequent key presses leave KeyPressed stuck at the first character that was typed (viewing in the Watch window while debugging).  Once I grab that key (I am adding it to a buffer) how do I get the next key pressed to be captured by this function?

--- End quote ---
I'm not experiencing that behavior with TMemo.OnKeyPress, probably your problem lies somewhere else.

Lazarus 2.2.4 (rev lazarus_2_2_4) FPC 3.2.2 x86_64-linux-gtk2

Navigation

[0] Message Index

[#] Next page

Go to full version