Can i press 2 key at the same time? lazarus / 61-Beginners ---------------------------------------------------------------------- Emperor2503 · 2021-11-19 08:13 So there's a character when u press left keys, he going to left, when you press right keys, he going to right, when u press up keys, he going to jump. so the problem is, when i press up keys and left keys(both together at the same time), only left keys work. So how to make them work together when we press both key together at the same time? (Sorry I'm new at programming) ---------------------------------------------------------------------- MarkMLl · 2021-11-19 08:17 Depends entirely on your operating system and hardware. MarkMLl ---------------------------------------------------------------------- Emperor2503 · 2021-11-19 08:24 uhm I don't get what did you mean, sorry. But can you take a look my program that I post? Untitled2.pas one ---------------------------------------------------------------------- Emperor2503 · 2021-11-19 08:36 At the program, can I press button #72 and button #77 at the same time? ---------------------------------------------------------------------- Seenkao · 2021-11-19 08:53 Я не помню насчёт Readkey. В простых графических программах, при опросе клавиатуры, делаю флаги указывающие произошедшее событие. Четыре события (up, left, right, down) и для них четыре флага, указывающие, что они были нажаты в данный момент времени. Первое: вам надо убрать из "main" при опросе все "else" и опрашивать клавиши последовательно. Второе: надо будет произвести выборку когда нажаты диаметрально противоположные клавиши и обнулить их. Третье: вам нужна будет процедура, которая будет обрабатывать флаги с учётом произошедших событий. При выполнении этих условий персонаж сможет двигаться по диагонали. В вашем коде это надо дополнительно переделывать. Тут есть одна проблема... Я в программах проверяю клавиши отжатия и отключаю флаги нажатий... как это будет происходить в данном случае? 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   if keyDown = Left then    flagLeft := true  else    flagLeft := false;может быть в подобном варианте? google translate: I don't remember about the Readkey. In simple graphical programs, when polling the keyboard, I make flags indicating the event that occurred. Four events (up, left, right, down) and for them four flags indicating that they were pressed at a given time. First: you need to remove all "else" from "main" when polling and poll the keys sequentially. Second: it will be necessary to make a selection when diametrically opposite keys are pressed and reset them. Third: you will need a procedure that will process the flags taking into account the events that have occurred. If these conditions are met, the character will be able to move diagonally. In your code, this needs to be further redone. There is one problem here... I check the pressing keys in the programs and disable the pressing flags... how will this happen in this case? 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   if keyDown = Left then        flag Left := true  else    flagLeft := false;can it be in a similar variant? ---------------------------------------------------------------------- Emperor2503 · 2021-11-19 09:16 I still don't get it can you give me another example? or can you explain to me more detail? I'm new at programming, I'm so sorry Edit : I'm using dev-pascal ---------------------------------------------------------------------- Kays · 2021-11-19 09:39 Quote from: Emperor2503 on November 19, 2021, 09:24:14 amuhm I don't get what did you mean, sorry.Just No. It won’t work reliably. For more on the underlying technical issue https://en.wikipedia.org/wiki/Rollover_(keyboard) ---------------------------------------------------------------------- Handoko · 2021-11-19 10:29 Can be done easily in Lazarus. 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, Forms, Graphics, ExtCtrls, LCLType; type   { TForm1 }   TForm1 = class(TForm)    shpSprite: TShape;    shpUp: TShape;    shpDown: TShape;    shpLeft: TShape;    shpRight: TShape;    Timer1: TTimer;    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);    procedure FormCreate(Sender: TObject);    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure Timer1Timer(Sender: TObject);  private    FKup, FKdown, FKleft, FKright: Boolean;  end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  case Key of    VK_UP:    FKup    := True;    VK_DOWN:  FKdown  := True;    VK_LEFT:  FKleft  := True;    VK_RIGHT: FKright := True;  end;end; procedure TForm1.FormCreate(Sender: TObject);begin  FKup                := False;  FKdown                := False;  FKleft              := False;  FKright               := False;  Timer1.Interval     := 20;  shpSprite.Shape       := stCircle;  shpSprite.Brush.Color := clGreen;end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);begin  Timer1.Enabled := False;end; procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);begin  case Key of    VK_UP:    FKup    := False;    VK_DOWN:  FKdown  := False;    VK_LEFT:  FKleft  := False;    VK_RIGHT: FKright := False;  end;end; procedure TForm1.Timer1Timer(Sender: TObject);begin   if FKup then    shpUp.Brush.Color := clRed  else    shpUp.Brush.Color := clWhite;  if FKdown then    shpDown.Brush.Color := clRed  else    shpDown.Brush.Color := clWhite;  if FKleft then    shpLeft.Brush.Color := clRed  else    shpLeft.Brush.Color := clWhite;  if FKright then    shpRight.Brush.Color := clRed  else    shpRight.Brush.Color := clWhite;   if FKup    then shpSprite.Top  := shpSprite.Top - 1;  if FKdown  then shpSprite.Top  := shpSprite.Top + 1;  if FKleft  then shpSprite.Left := shpSprite.Left - 1;  if FKright then shpSprite.Left := shpSprite.Left + 1;   if shpSprite.Top < -shpSprite.Height then    shpSprite.Top := Height;  if shpSprite.Top > Height then    shpSprite.Top := -shpSprite.Height;  if shpSprite.Left < -shpSprite.Width then    shpSprite.Left := Width;  if shpSprite.Left > Width then    shpSprite.Left := -shpSprite.Width; end; end. ---------------------------------------------------------------------- Emperor2503 · 2021-11-19 10:41 So at dev-pascal it won't work Okk so, i got another more question, Did you guys know where i can learn more about lazarus(i just try to use it recently). Something like unit, classes ,etc. ---------------------------------------------------------------------- Handoko · 2021-11-19 10:58 Learning Lazarus should be easier, it has plenty of properly-written ready-to-use components. If you want to learn writing games, read here: https://forum.lazarus.freepascal.org/index.php/topic,57117.msg424624.h tml#msg424624 If you're new in Pascal programming, you start from here: https://wiki.freepascal.org/Basic_Pascal_Tutorial https://wiki.freepascal.org/Free_Pascal_videos https://wiki.freepascal.org/Lazarus_videos If you want to learn more about the Lazarus IDE: https://wiki.freepascal.org/Lazarus_Tutorial You should bookmark these: https://www.freepascal.org/docs-html/current/user/user.html https://www.freepascal.org/docs-html/current/prog/prog.html https://www.freepascal.org/docs-html/current/ref/ref.html ---------------------------------------------------------------------- Emperor2503 · 2021-11-19 11:20 Ok thank you so much sirr ---------------------------------------------------------------------- VTwin · 2021-11-20 00:19 Lovely example Handoko! You are an excellent ambassador for Free Pascal and Lazarus.