Recent

Author Topic: [SOLVED] How to detect touchscreen?  (Read 1074 times)

dsiders

  • Full Member
  • ***
  • Posts: 208
[SOLVED] How to detect touchscreen?
« on: January 10, 2019, 01:36:35 pm »
I am wondering how to detect if a touch-enabled device is attached during form creation/display. It is needed to adjust font and control sizes and alignment for UI controls that are just too small for touch usage.

Any ideas? Neither Google nor Forum Search were very helpful on this topic.

Thanks in advance.
« Last Edit: January 10, 2019, 02:49:30 pm by dsiders »
Lazarus 2.0.2 / FPC 3.0.4 / Windows 8.1 64-bit

tr_escape

  • Sr. Member
  • ****
  • Posts: 378
  • sector name toys | respect to spectre
    • Github:

josh

  • Hero Member
  • *****
  • Posts: 743
Re: How to detect touchscreen?
« Reply #2 on: January 10, 2019, 02:27:17 pm »
Hi

Windows getsystemmetrics maybe the route to go.

I have not tested; but should be ok.

Code: [Select]
VAR Touch_Screen_Enabled:Boolean=True;
begin
  Touch_Screen_Enabled:=GetSystemMetrics(SM_MAXIMUMTOUCHES)>0;                                   

note need to add windows to uses
« Last Edit: January 10, 2019, 02:30:36 pm by josh »
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

dsiders

  • Full Member
  • ***
  • Posts: 208
Re: How to detect touchscreen?
« Reply #3 on: January 10, 2019, 02:49:17 pm »
Windows getsystemmetrics maybe the route to go.

I have not tested; but should be ok.

Code: [Select]
VAR Touch_Screen_Enabled:Boolean=True;
begin
  Touch_Screen_Enabled:=GetSystemMetrics(SM_MAXIMUMTOUCHES)>0;                                   

note need to add windows to uses

Thanks Josh. This does in fact work for Windows. Looks like lcltype.pp needs a refresh though... it doesn't have some the SM_* values from the MSDN docs.

Now I need to poke around and see how Linux handles this.

Thanks again.
Lazarus 2.0.2 / FPC 3.0.4 / Windows 8.1 64-bit

dsiders

  • Full Member
  • ***
  • Posts: 208
Re: How to detect touchscreen?
« Reply #4 on: January 10, 2019, 03:47:16 pm »
Now I need to poke around and see how Linux handles this.

So far, all I have found that seems remotely distro-independent is capturing output from udevadm info. The search continues...
Lazarus 2.0.2 / FPC 3.0.4 / Windows 8.1 64-bit