Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for touchdetect.cs

(view source code of touchdetect.cs as plain text)

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4.  
  5.  
  6. namespace RobvanderWoude
  7. {
  8. 	class TouchDetect
  9. 	{
  10. 		static string progver = "0.10 alpha";
  11.  
  12.  
  13. 		static int Main( string[] args )
  14. 		{
  15. 			if ( args.Length > 0 )
  16. 			{
  17. 				return ShowHelp( );
  18. 			}
  19.  
  20. 			try
  21. 			{
  22. 				if ( GetSystemMetrics( 95 ) > 0 )
  23. 				{
  24. 					Console.WriteLine( "Touch enabled device(s) detected" );
  25. 					return 0;
  26. 				}
  27. 				else
  28. 				{
  29. 					Console.WriteLine( "No touch enabled devices detected" );
  30. 					return 2;
  31. 				}
  32. 			}
  33. 			catch ( Exception e )
  34. 			{
  35. 				return ShowHelp( e.Message );
  36. 			}
  37. 		}
  38.  
  39.  
  40. 		static int ShowHelp( params string[] errmsg )
  41. 		{
  42. 			#region Error Message
  43.  
  44. 			if ( errmsg.Length > 0 )
  45. 			{
  46. 				List<string> errargs = new List<string>( errmsg );
  47. 				errargs.RemoveAt( 0 );
  48. 				Console.Error.WriteLine( );
  49. 				Console.ForegroundColor = ConsoleColor.Red;
  50. 				Console.Error.Write( "ERROR:\t" );
  51. 				Console.ForegroundColor = ConsoleColor.White;
  52. 				Console.Error.WriteLine( errmsg[0], errargs.ToArray( ) );
  53. 				Console.ResetColor( );
  54. 			}
  55.  
  56. 			#endregion Error Message
  57.  
  58. 			#region Help Text
  59.  
  60. 			/*
  61. 			TouchDetect.exe,  Version 0.10 alpha
  62. 			Check if touch enabled devices are available
  63.  
  64. 			Usage:  TouchDetect.exe
  65.  
  66. 			Note:   Return code will be 0 if a touch enabled device is detected,
  67. 			        1 for errors, 2 if no touch enabled device was detected.
  68.  
  69. 			Written by Rob van der Woude
  70. 			http://www.robvanderwoude.com
  71. 			*/
  72.  
  73. 			Console.Error.WriteLine( );
  74.  
  75. 			Console.Error.WriteLine( "TouchDetect.exe,  Version {0}", progver );
  76.  
  77. 			Console.Error.WriteLine( "Check if touch enabled devices are available" );
  78.  
  79. 			Console.Error.WriteLine( );
  80.  
  81. 			Console.Error.Write( "Usage:  " );
  82. 			Console.ForegroundColor = ConsoleColor.White;
  83. 			Console.Error.WriteLine( "TouchDetect.exe" );
  84. 			Console.ResetColor( );
  85.  
  86. 			Console.Error.WriteLine( );
  87.  
  88. 			Console.Error.WriteLine( "Note:   Return code will be 0 if a touch enabled device is detected," );
  89.  
  90. 			Console.Error.WriteLine( "        1 for errors, 2 if no touch enabled device was detected." );
  91.  
  92. 			Console.Error.WriteLine( );
  93.  
  94. 			Console.Error.WriteLine( "Written by Rob van der Woude" );
  95.  
  96. 			Console.Error.WriteLine( "http://www.robvanderwoude.com" );
  97.  
  98. 			#endregion Help Text
  99.  
  100. 			return 1;
  101. 		}
  102.  
  103.  
  104. 		[DllImport( "user32.dll" )]
  105. 		public static extern int GetSystemMetrics( int smIndex );
  106. 	}
  107. }
  108.  

page last modified: 2024-04-16; loaded in 0.0074 seconds