Jump to content
Sign in to follow this  
Bernard

Touch Screen VCL

Recommended Posts

Hello Everyone,

 

I have been moving to a keyboard mouse free interface on a machine. I have introduced a Touchscreen interface on a machine running Windows 10 Pro.


Issue.


On the screen there are a few buttons that jog motors.

When you press the key it will not register unless you move (wiggle) your finger about on the screen.

 

 

So the functionality (on touch screen with finger) I am looking for is...

 

Press and hold button.   Motor starts moving.

Release button.  Motor stops.


Thank you.

Share this post


Link to post

How is your screen performing this? There are basically two options

  1. It's using "true" touch functionality, like on a regular Tablet (like Surface)
  2. It is emulating a regular mouse. Which means a mouse pointer will always be stuck on screen. Right-clicking is usually done by long-pressing

It sounds like your screen is using option 2.

If possible, see if it can be configured to use option one.

 

If not, you have to have to disable the "long-press to right-click" functionality, if you don't need it.

 

If that's not an option, it can be adjusted in the VCL itself, every TControl has a TabletOption where the long-press behaviour can be adjusted. That's how I remember it, I could be wrong.

Share this post


Link to post

For every component is possible, in gesture options, disable the long press event (PRESSANDHOLD) to not enter in "simulated right mouse click" and perform what you need.

You can also perform that in WndProc (for e.g. in custom components) when you use old Dephi versions (e.g BDS2006 or any version with don't have gesture management):

 

procedure TAggButton.WndProc(var Message: TMessage);
const
  WM_TABLET_DEFBASE                     = $02C0;
  WM_TABLET_QUERYSYSTEMGESTURESTATUS    = (WM_TABLET_DEFBASE + 12);
const
  TABLET_DISABLE_PRESSANDHOLD           = $00000001;
  TABLET_DISABLE_PENTAPFEEDBACK         = $00000008;
  TABLET_DISABLE_PENBARRELFEEDBACK      = $00000010;
  TABLET_DISABLE_TOUCHUIFORCEON         = $00000100;
  TABLET_DISABLE_TOUCHUIFORCEOFF        = $00000200;
  TABLET_DISABLE_TOUCHSWITCH            = $00008000;
  TABLET_DISABLE_FLICKS                 = $00010000;
  TABLET_ENABLE_FLICKSONCONTEXT         = $00020000;
  TABLET_ENABLE_FLICKLEARNINGMODE       = $00040000;
  TABLET_DISABLE_SMOOTHSCROLLING        = $00080000;
  TABLET_DISABLE_FLICKFALLBACKKEYS      = $00100000;
  TABLET_ENABLE_MULTITOUCHDATA          = $01000000;

  {**
   *  NOTE
   *  ====
   *  https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-cursorinfo
   *
   *    CI.flags:
   *
   *                      0           The cursor is hidden.
   *    CURSOR_SHOWING    0x00000001  The cursor is showing.
   *    CURSOR_SUPPRESSED 0x00000002  Windows 8: The cursor is suppressed.
   *                                  This flag indicates that the system is not drawing the cursor because the user is
   *                                  providing input through touch or pen instead of the mouse.
   *
   *  Minimum supported client	Windows 2000 Professional [desktop apps only].
   *
   **}
  function IsMouseCursorVisible: Boolean;
  var
    CI: TCursorInfo;
  begin
    CI.cbSize := SizeOf(CI);
    Result := GetCursorInfo(CI) and (CI.flags = CURSOR_SHOWING);
  end;

begin
  case Message.Msg of
    CM_TEXTCHANGED:
      Invalidate;
    CM_VISIBLECHANGED:
    begin
      Invalidate;
    end;
    CM_ENABLEDCHANGED:
    begin
      FSVGSupportChanged := True;
      Invalidate;
    end;
    CM_MOUSEENTER:
    begin
      if not FMouseInControl then
      begin
        FMouseInControl := IsMouseCursorVisible;
        if FMouseInControl then Invalidate;
      end;
    end;
    CM_MOUSELEAVE:
    begin
      if FMouseInControl then
      begin
        FMouseInControl := False;
        Invalidate;
      end;
    end;
    WM_ERASEBKGND:
    begin
      Message.Result := 1;
      Exit;
    end;
    WM_MOUSELEAVE:
    begin
    end;
    WM_TABLET_QUERYSYSTEMGESTURESTATUS:
    begin
      Message.Result :=
      (
        TABLET_DISABLE_PRESSANDHOLD or
        TABLET_DISABLE_PENTAPFEEDBACK or
        TABLET_DISABLE_PENBARRELFEEDBACK or
        TABLET_DISABLE_TOUCHUIFORCEON or
        TABLET_DISABLE_TOUCHUIFORCEOFF or
        TABLET_DISABLE_TOUCHSWITCH or
        TABLET_DISABLE_FLICKS or
        TABLET_DISABLE_SMOOTHSCROLLING or
        TABLET_DISABLE_FLICKFALLBACKKEYS
      );
      Exit;
    end;
  end;
  inherited WndProc(Message);
end;

In this case you have also to enable touch management with:

 

    procedure CreateWnd; override;
    procedure DestroyWnd; override;

procedure TAggButton.CreateWnd;
begin
  inherited;

  if csLoading in ComponentState then Exit;
  if not FTouchInitialized and TOSVersion.Check(6, 1) and RegisterTouchWindow(Handle, 0) then
    FTouchInitialized := True;
end;

procedure TAggButton.DestroyWnd;
begin
  if FTouchInitialized then
  begin
    UnregisterTouchWindow(Handle);
    FTouchInitialized := False;
  end;

  inherited;
end;

 

Edited by shineworld

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×