(view source code of touchdetect.cs as plain text)
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace RobvanderWoude
{
class TouchDetect
{
static string progver = "0.10 alpha";
static int Main( string[] args )
{
if ( args.Length > 0 )
{
return ShowHelp( );
}
try
{
if ( GetSystemMetrics( 95 ) > 0 )
{
Console.WriteLine( "Touch enabled device(s) detected" );
return 0;
}
else
{
Console.WriteLine( "No touch enabled devices detected" );
return 2;
}
}
catch ( Exception e )
{
return ShowHelp( e.Message );
}
}
static int ShowHelp( params string[] errmsg )
{
#region Error Message
if ( errmsg.Length > 0 )
{
List<string> errargs = new List<string>( errmsg );
errargs.RemoveAt( 0 );
Console.Error.WriteLine( );
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.Write( "ERROR:\t" );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( errmsg[0], errargs.ToArray( ) );
Console.ResetColor( );
}
#endregion Error Message
#region Help Text
/*
TouchDetect.exe, Version 0.10 alpha
Check if touch enabled devices are available
Usage: TouchDetect.exe
Note: Return code will be 0 if a touch enabled device is detected,
1 for errors, 2 if no touch enabled device was detected.
Written by Rob van der Woude
http://www.robvanderwoude.com
*/
Console.Error.WriteLine( );
Console.Error.WriteLine( "TouchDetect.exe, Version {0}", progver );
Console.Error.WriteLine( "Check if touch enabled devices are available" );
Console.Error.WriteLine( );
Console.Error.Write( "Usage: " );
Console.ForegroundColor = ConsoleColor.White;
Console.Error.WriteLine( "TouchDetect.exe" );
Console.ResetColor( );
Console.Error.WriteLine( );
Console.Error.WriteLine( "Note: Return code will be 0 if a touch enabled device is detected," );
Console.Error.WriteLine( " 1 for errors, 2 if no touch enabled device was detected." );
Console.Error.WriteLine( );
Console.Error.WriteLine( "Written by Rob van der Woude" );
Console.Error.WriteLine( "http://www.robvanderwoude.com" );
#endregion Help Text
return 1;
}
[DllImport( "user32.dll" )]
public static extern int GetSystemMetrics( int smIndex );
}
}
page last modified: 2024-04-16; loaded in 0.0074 seconds