While in Canvas how to read inputs from users? lazarus / 39-Graphics ---------------------------------------------------------------------- Groeneg · 2020-07-08 09:04 I am programming a simulation using Canvas and it works fine and looks good. Nice graphics and text outputs work fine. However I now want to use user input to control the flow of the simulation. 1. Wait until user presses key 2. Increase animation speed by pressing +/- (decrease and increase delay value) 3. End generation by pressing N 3. End simulation by pressing Q And so on. But if I use Keypressed or Read etc. it doesn't work. I think it is because the latter functions only work in CRT mode but I'm not sure. So if there are any tips, pointers or examples I would much appreciate it. With regards Gerard ---------------------------------------------------------------------- Ñuño_Martínez · 2020-07-08 10:45 Try with TForm events related with keys, they are OnKeyDown, OnKeyPress and OnKeyUp ---------------------------------------------------------------------- winni · 2020-07-08 10:52 Hi! As Ñuño_Martínez said: use the keyboard events of the main form. Set the KeyboardPreview of Form1 in the OI to true. Connect to the keypress event of Form1: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);begincase Key of'+' : .....'-' :  ....'N': .....'Q': self.close;end; // caseend;  Winni ---------------------------------------------------------------------- Groeneg · 2020-07-08 12:11 Ok thanks, I will try this and keep you posted. ---------------------------------------------------------------------- Handoko · 2020-07-08 13:42 KeyPress, KeyUp and KeyDown are okay for GUI applications but for animations or games I recommend GetKeyState, using it you can get smooth even inertia movement. You can get the demo on recent versions of Lazarus: Lazarus main menu > Tools > Example Projects > provide the keyword: sprite For your information, don't open any demo directly from the source. It is better to copy it to a new location (for example Desktop) to prevent security or other issues. If you interested to learn from the previous discussion, here: https://forum.lazarus.freepascal.org/index.php/topic,41178.msg285678.h tml#msg285678