Touch Features in EWB
by Erick Engelke
January 13, 2024
In my last blog article I made a space invaders styled game. But it didn’t work on many tablets, because they use Touch events and I didn’t program that in.
So I wrote a simple program to test Touch events: test program
You can use it to see which events are generated on your tablet.
-
when you touch the screen, the message sent is TouchStart
-
if you tap the screen, the TouchStart is sent then a TouchEnd
-
if you drag across the screen, a TouchStart followed by TouchMove’s but no TouchEnd is sent
-
successive moves just add more TouchMoves, with no TouchStart or TouchEnd.
Here’s the simple source code:[source,]
unit touchgui;
interface
uses WebCore, WebUI, WebForms, WebCtrls, WebLabels;
type
TForm1 = class(TForm)
HTMLLabel1: THTMLLabel;
procedure HTMLLabel1TouchCancel(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
procedure HTMLLabel1TouchEnd(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
procedure HTMLLabel1TouchMove(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
procedure HTMLLabel1TouchStart(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
private
{ Private declarations }
procedure Label( s : string );
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
procedure TForm1.Label( s : string );
begin
HTMLLabel1.Content := s + '<br>' + htmlLabel1.Content;
end;
procedure TForm1.HTMLLabel1TouchCancel(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
begin
label( 'Touch Cancel (x:'+IntToStr(x )+', y:' +inttostr( y )+')');
end;
procedure TForm1.HTMLLabel1TouchEnd(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
begin
label( 'Touch End (x:'+IntToStr(x )+', y:' +inttostr( y )+')');
end;
procedure TForm1.HTMLLabel1TouchMove(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
begin
label( 'Touch Move (x:'+IntToStr(x )+', y:' +inttostr( y )+')');
end;
procedure TForm1.HTMLLabel1TouchStart(Sender: TObject; ShiftKey: Boolean;
CtrlKey: Boolean; AltKey: Boolean;
X: Integer; Y: Integer);
begin
label( 'Touch Start (x:'+IntToStr(x )+', y:' +inttostr( y )+')');
end;
end.