1
votes

I have 2 laptops with inbuilt multitouch capable Trackpads, one is an Acer Switch and the other an ASUS Zenbook and have been trying to make my Delphi apps gesture aware.

I had thought that trackpad gestures would map to touchscreen gestures but this does not appear to be so as pinching to zoom or panning on the trackpad does not trigger the ongesture event.

The trackpad gestures work on other applications like Firefox so it must be possible to capture them.

It appears the two finger vertical scroll gets mapped into Delphi mousewheelup and mousewheel down events. I can't seem to figure out how to capture other types of events.

any clues on how to do this?

Update - I found the MS documentation on trackpad gestures, it appears they are converted to mouse wheel events.

https://msdn.microsoft.com/en-us/library/windows/hardware/dn614021(v=vs.85).aspx

It appears there is a bug in the Delphi mouse capturing of these messages in that it does not capture Horizontal mouse wheel messages.

Also the trackpad vertical pan produces the opposite scroll direction to the mouse wheel scroll.

1

1 Answers

0
votes

Since no one managed to answer this, I guess its a new problem that has not been addressed so I did the digging and came up with a solution, the code of which is below.

This code handles all the common mouse and trackpad gestures of panning and zooming. All these gestures are routed through mousewheel events. The additional overridden WndProc captures the horizontal events which are missing from the Delphi event manager.

procedure TmyFrame.WndProc(var Message:TMessage);
begin
  if Message.Msg=WM_MOUSEHWHEEL then
  begin
    if TWMMouseWheel(Message).Keys=0 then
    begin     //Scrollbars are assumed to have 1000 positions
      with HorzScrollBar do
        Position := Position+TWMMouseWheel(Message).WheelDelta div 10;
      Message.Result := 0;
    end else
      Message.Result := 1;
  end else
    inherited;
end;

procedure TmyFrame.FrameMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var n:integer;
begin
  Accum:=Accum+wheeldelta;   //We need an accumulator as trackpad deltas are little and often
  n:=Accum div 30;
  if n=0 then exit;
  Accum:=0;
  if ssctrl in shift then   //pinch zoom
  begin
    Zoomfunc(1-sign(WheelDelta)/50);  // 2% granularity ie 0.98 is -2% shrink
  end else
  if ssshift in shift then
  with HorzScrollBar do   //horiz using shift-mouswheel
    position:=position+n
  else
  with VertScrollBar do   //vert scroll
  begin
    position:=position-n;
  end;
  handled:=true;
end;