2019-10-05 17:49:56 +02:00
|
|
|
|
using CC_Functions.W32;
|
|
|
|
|
using System;
|
2019-07-23 14:54:05 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2019-08-01 22:42:35 +02:00
|
|
|
|
using System.Windows.Input;
|
2019-07-23 14:54:05 +02:00
|
|
|
|
|
|
|
|
|
namespace Base
|
|
|
|
|
{
|
2019-10-05 17:49:56 +02:00
|
|
|
|
public static class Input
|
2019-07-23 14:54:05 +02:00
|
|
|
|
{
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check whether the Key is pressed
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="key">Key to check</param>
|
|
|
|
|
/// <returns>Whether the key is pressed</returns>
|
2019-07-23 14:54:05 +02:00
|
|
|
|
public static bool IsKeyDown(Keys key)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-10-05 17:49:56 +02:00
|
|
|
|
return KeyboardReader.IsKeyDown(key);
|
2019-07-23 14:54:05 +02:00
|
|
|
|
}
|
2019-10-05 17:49:56 +02:00
|
|
|
|
catch (Exception e)
|
2019-07-23 14:54:05 +02:00
|
|
|
|
{
|
2019-10-05 17:49:56 +02:00
|
|
|
|
Console.WriteLine("Invader: IsKeyDown failed:\r\n" + e.ToString());
|
2019-07-23 14:54:05 +02:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-25 16:21:07 +02:00
|
|
|
|
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unified input for going up
|
|
|
|
|
/// </summary>
|
2019-08-25 16:21:07 +02:00
|
|
|
|
public static bool Up => IsKeyDown(Keys.Up) || IsKeyDown(Keys.W);
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unified input for going left
|
|
|
|
|
/// </summary>
|
2019-08-25 16:21:07 +02:00
|
|
|
|
public static bool Left => IsKeyDown(Keys.Left) || IsKeyDown(Keys.A);
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unified input for going down
|
|
|
|
|
/// </summary>
|
2019-08-25 16:21:07 +02:00
|
|
|
|
public static bool Down => IsKeyDown(Keys.Down) || IsKeyDown(Keys.S);
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unified input for going right
|
|
|
|
|
/// </summary>
|
2019-08-25 16:21:07 +02:00
|
|
|
|
public static bool Right => IsKeyDown(Keys.Right) || IsKeyDown(Keys.D);
|
2019-09-19 18:51:31 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unified input for doing something
|
|
|
|
|
/// </summary>
|
2019-08-25 16:21:07 +02:00
|
|
|
|
public static bool Action => IsKeyDown(Keys.Space) || IsKeyDown(Keys.Q) || IsKeyDown(Keys.E);
|
2019-07-23 14:54:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|