Mega Code Archive

 
Categories / Delphi / Hardware
 

Detect touch input capabilities

Title: Detect touch input capabilities Question: With the upcomming versions of both Delphi 2010 and Windows 7, more and more people will start to write touch enabled applications. Below you will find a small piece of code that let you detect what kind of capabilities the current system has regarding input with pen/finger. Answer: const SM_DIGITIZER = 94; TABLET_CONFIG_NONE = $00000000; //The input digitizer does not have touch capabilities. NID_INTEGRATED_TOUCH = $00000001; //An integrated touch digitizer is used for input. NID_EXTERNAL_TOUCH = $00000002; //An external touch digitizer is used for input. NID_INTEGRATED_PEN = $00000004; //An integrated pen digitizer is used for input. NID_EXTERNAL_PEN = $00000008; //An external pen digitizer is used for input. NID_MULTI_INPUT = $00000040; //An input digitizer with support for multiple inputs is used for input. NID_READY = $00000080; //The input digitizer is ready for input. If this value is unset, it may mean that the tablet service is stopped, the digitizer is not supported, or digitizer drivers have not been installed. type TTouchCapability = (tcTabletPC,tcIntTouch,tcExtTouch,tcIntPen,tcExtPen,tcMultiTouch,tcReady); TTouchCapabilities = set of TTouchCapability; function GetTouchCapabilities : TTouchCapabilities; var ADigitizer : integer; begin result := []; // First check if the system is a TabletPC if GetSystemMetrics(SM_TABLETPC) 0 then begin include(result,tcTabletPC); if CheckWin32Version(6,1) then begin // If Windows 7, then we can do additional tests on input type ADigitizer := GetSystemMetrics(SM_DIGITIZER); if ((ADigitizer and NID_INTEGRATED_TOUCH)&lt&gt0) then include(result,tcIntTouch); if ((ADigitizer and NID_EXTERNAL_TOUCH)&lt&gt0) then include(result,tcExtTouch); if ((ADigitizer and NID_INTEGRATED_PEN)&lt&gt0) then include(result,tcIntPen); if ((ADigitizer and NID_EXTERNAL_PEN)&lt&gt0) then include(result,tcExtPen); if ((ADigitizer and NID_MULTI_INPUT)&lt&gt0) then include(result,tcMultiTouch); if ((ADigitizer and NID_READY)&lt&gt0) then include(result,tcReady); end else begin // If not Windows7 and TabletPC detected, we asume that it's ready include(result,tcReady); end; end; end; procedure TForm1.Button1Click(Sender: TObject); var ATouchSupport : TTouchCapabilities; begin ATouchSupport := GetTouchCapabilities; if (tcTabletPC in ATouchSupport) then Memo1.Lines.Add('tcTabletPC'); if (tcIntTouch in ATouchSupport) then Memo1.Lines.Add('tcIntTouch'); if (tcExtTouch in ATouchSupport) then Memo1.Lines.Add('tcExtTouch'); if (tcIntPen in ATouchSupport) then Memo1.Lines.Add('tcIntPen'); if (tcExtPen in ATouchSupport) then Memo1.Lines.Add('tcExtPen'); if (tcMultiTouch in ATouchSupport) then Memo1.Lines.Add('tcMultiTouch'); if (tcReady in ATouchSupport) then Memo1.Lines.Add('tcReady'); end;