diff --git a/Source/OpenTK/Input/GamePadButtons.cs b/Source/OpenTK/Input/GamePadButtons.cs
index 3910d2e1..aba12d47 100644
--- a/Source/OpenTK/Input/GamePadButtons.cs
+++ b/Source/OpenTK/Input/GamePadButtons.cs
@@ -140,6 +140,19 @@ namespace OpenTK.Input
get { return GetButton(Buttons.Start); }
}
+ ///
+ /// Gets a value indicating whether any button is pressed.
+ ///
+ /// true if any button is pressed; otherwise, false.
+ public bool IsAnyButtonPressed
+ {
+ get
+ {
+ // If any bit is set then a button is down.
+ return buttons != 0;
+ }
+ }
+
/// A instance to test for equality.
/// A instance to test for equality.
public static bool operator ==(GamePadButtons left, GamePadButtons right)
diff --git a/Source/OpenTK/Input/JoystickState.cs b/Source/OpenTK/Input/JoystickState.cs
index 1ecb562b..540d5c74 100644
--- a/Source/OpenTK/Input/JoystickState.cs
+++ b/Source/OpenTK/Input/JoystickState.cs
@@ -123,6 +123,19 @@ namespace OpenTK.Input
return (buttons & (1 << (int)button)) == 0;
}
+ ///
+ /// Gets a value indicating whether any button is down.
+ ///
+ /// true if any button is down; otherwise, false.
+ public bool IsAnyButtonDown
+ {
+ get
+ {
+ // If any bit is set then a button is down.
+ return buttons != 0;
+ }
+ }
+
///
/// Gets a value indicating whether this instance is connected.
///
diff --git a/Source/OpenTK/Input/KeyboardState.cs b/Source/OpenTK/Input/KeyboardState.cs
index 2a61cd22..2071ae95 100644
--- a/Source/OpenTK/Input/KeyboardState.cs
+++ b/Source/OpenTK/Input/KeyboardState.cs
@@ -39,7 +39,7 @@ namespace OpenTK.Input
#region Fields
// Allocate enough ints to store all keyboard keys
- const int IntSize = sizeof(int);
+ const int IntSize = sizeof(int) * 8;
const int NumInts = ((int)Key.LastKey + IntSize - 1) / IntSize;
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
unsafe fixed int Keys[NumInts];
@@ -108,6 +108,33 @@ namespace OpenTK.Input
return !IsKeyDown(code);
}
+ ///
+ /// Gets a value indicating whether any key is down.
+ ///
+ /// true if any key is down; otherwise, false.
+ public bool IsAnyKeyDown
+ {
+ get
+ {
+ // If any bit is set then a key is down.
+ unsafe
+ {
+ fixed (int* k = Keys)
+ {
+ for(int i = 0; i < NumInts; ++i)
+ {
+ if (k[i] != 0)
+ {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+ }
+
///
/// Gets a indicating whether this keyboard
/// is connected.
@@ -226,8 +253,8 @@ namespace OpenTK.Input
{
ValidateOffset(offset);
- int int_offset = offset / 32;
- int bit_offset = offset % 32;
+ int int_offset = offset / IntSize;
+ int bit_offset = offset % IntSize;
unsafe
{
fixed (int* k = Keys) { return (*(k + int_offset) & (1 << bit_offset)) != 0u; }
@@ -238,8 +265,8 @@ namespace OpenTK.Input
{
ValidateOffset(offset);
- int int_offset = offset / 32;
- int bit_offset = offset % 32;
+ int int_offset = offset / IntSize;
+ int bit_offset = offset % IntSize;
unsafe
{
fixed (int* k = Keys) { *(k + int_offset) |= 1 << bit_offset; }
@@ -250,8 +277,8 @@ namespace OpenTK.Input
{
ValidateOffset(offset);
- int int_offset = offset / 32;
- int bit_offset = offset % 32;
+ int int_offset = offset / IntSize;
+ int bit_offset = offset % IntSize;
unsafe
{
fixed (int* k = Keys) { *(k + int_offset) &= ~(1 << bit_offset); }
diff --git a/Source/OpenTK/Input/MouseState.cs b/Source/OpenTK/Input/MouseState.cs
index 9c316e01..a8193401 100644
--- a/Source/OpenTK/Input/MouseState.cs
+++ b/Source/OpenTK/Input/MouseState.cs
@@ -173,6 +173,19 @@ namespace OpenTK.Input
get { return IsButtonDown(MouseButton.Button2) ? ButtonState.Pressed : ButtonState.Released; }
}
+ ///
+ /// Gets a value indicating whether any button is down.
+ ///
+ /// true if any button is down; otherwise, false.
+ public bool IsAnyButtonDown
+ {
+ get
+ {
+ // If any bit is set then a button is down.
+ return buttons != 0;
+ }
+ }
+
///
/// Gets the absolute wheel position in integer units. This property is intended for XNA compatibility.
/// To support high-precision mice, it is recommended to use instead.