00001 #region License 00002 // 00003 // The Open Toolkit Library License 00004 // 00005 // Copyright (c) 2006 - 2009 the Open Toolkit library. 00006 // 00007 // Permission is hereby granted, free of charge, to any person obtaining a copy 00008 // of this software and associated documentation files (the "Software"), to deal 00009 // in the Software without restriction, including without limitation the rights to 00010 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 00011 // the Software, and to permit persons to whom the Software is furnished to do 00012 // so, subject to the following conditions: 00013 // 00014 // The above copyright notice and this permission notice shall be included in all 00015 // copies or substantial portions of the Software. 00016 // 00017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00018 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 00019 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00020 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 00021 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 00022 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00023 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00024 // OTHER DEALINGS IN THE SOFTWARE. 00025 // 00026 #endregion 00027 00028 using System; 00029 using System.Collections.Generic; 00030 using System.Text; 00031 00032 namespace OpenTK.Input 00033 { 00037 public struct KeyboardState : IEquatable<KeyboardState> 00038 { 00039 #region Fields 00040 00041 const int NumKeys = ((int)Key.LastKey + 16) / 32; 00042 // Todo: The following line triggers bogus CS0214 in gmcs 2.0.1, sigh... 00043 // Need to add a workaround using either ExplicitLayout or another trick. 00044 //unsafe fixed int Keys[NumKeys]; 00045 00046 #endregion 00047 00048 #region Constructors 00049 00050 #endregion 00051 00052 #region Public Members 00053 00058 public bool IsKeyDown(Key key) 00059 { 00060 return ReadBit((int)key) != 0; 00061 } 00062 00067 public bool IsKeyUp(Key key) 00068 { 00069 return ReadBit((int)key) == 0; 00070 } 00071 00072 #endregion 00073 00074 #region Internal Members 00075 00076 internal int ReadBit(int offset) 00077 { 00078 return 0; 00079 //unsafe { return (Keys[(offset / 32)] & (1 << (offset % 32))); } 00080 } 00081 00082 internal enum BitValue { Zero = 0, One = 1 } 00083 internal void WriteBit(int offset, BitValue bit) 00084 { 00085 // Todo: this is completely broken. 00086 //unsafe { Keys[offset / 32] = Keys[offset / 32] ^ (~(int)bit << (offset % 32)); } 00087 } 00088 00089 #endregion 00090 00091 #region IEquatable<KeyboardState> Members 00092 00098 public bool Equals(KeyboardState other) 00099 { 00100 throw new NotImplementedException(); 00101 } 00102 00103 #endregion 00104 } 00105 }
1.6.1