public static MyKeyboardState GetCurrentState() { MyKeyboardBuffer buffer = new MyKeyboardBuffer(); // Because GetKeyboardState cannot read from different than main thread /* unsafe { byte* keyData = stackalloc byte[256]; if (!GetKeyboardState(keyData)) { throw new InvalidOperationException("Could not read keyboard"); } CopyBuffer(keyData, ref buffer); } */ for (int i = 0; i < 256; i++) { if ((((ushort)GetAsyncKeyState(i)) >> 15) != 0) { buffer.SetBit((byte)i, true); } } return MyKeyboardState.FromBuffer(buffer); }
public static MyKeyboardState FromBuffer(MyKeyboardBuffer buffer) { return(new MyKeyboardState() { m_buffer = buffer }); }
public static MyKeyboardState GetCurrentState() { MyKeyboardBuffer buffer = new MyKeyboardBuffer(); // Because GetKeyboardState cannot read from different than main thread /* * unsafe * { * byte* keyData = stackalloc byte[256]; * * if (!GetKeyboardState(keyData)) * { * throw new InvalidOperationException("Could not read keyboard"); * } * * * CopyBuffer(keyData, ref buffer); * } */ for (int i = 0; i < 256; i++) { if ((((ushort)GetAsyncKeyState(i)) >> 15) != 0) { buffer.SetBit((byte)i, true); } } return(MyKeyboardState.FromBuffer(buffer)); }
static unsafe void CopyBuffer(byte* windowsKeyData, ref MyKeyboardBuffer buffer) { for (int i = 0; i < 256; i++) { if ((windowsKeyData[i] & 0x80) != 0) { buffer.SetBit((byte)i, true); } } }
static unsafe void CopyBuffer(byte *windowsKeyData, ref MyKeyboardBuffer buffer) { for (int i = 0; i < 256; i++) { if ((windowsKeyData[i] & 0x80) != 0) { buffer.SetBit((byte)i, true); } } }
public static MyKeyboardState FromBuffer(MyKeyboardBuffer buffer) { return new MyKeyboardState() { m_buffer = buffer }; }