Beispiel #1
0
 public static long SysSysMouseCount()
 {
     return(Windows.GetTickCount());
 }
Beispiel #2
0
        public static void KbdUpdateEventQueues()
        {
            AltNumericKey[] AltNumericKeys =
            {
                new AltNumericKey(0x9B00, 4),
                new AltNumericKey(0x9D00, 6),
                new AltNumericKey(0x9F00, 1),
                new AltNumericKey(0xA100, 3),
                new AltNumericKey(0x9700, 7),
                new AltNumericKey(0x9900, 9),
                new AltNumericKey(0x9800, 8),
                new AltNumericKey(0xA000, 2),
                new AltNumericKey(0xA200, 0),
                new AltNumericKey(0x4c00, 5)
            };

            System.UInt32  EventCount;
            INPUT_RECORD[] InRec = new INPUT_RECORD[1];
            bool           FoundAlt;
            byte           AltNumeric = 0;

            if (SysKeyCount > SysKeyQue.GetUpperBound(0))
            {
                return;
            }
            do
            {
                EventCount = 0;
                bool x = Windows.GetNumberOfConsoleInputEvents(Windows.GetStdHandle((int)StdHandles.STD_INPUT_HANDLE),
                                                               ref EventCount);
                if (EventCount == 0)
                {
                    return;
                }
                //Windows.ReadConsoleInput(Windows.GetStdHandle((int)StdHandles.STD_INPUT_HANDLE), ref InRec, out EventCount);
                Windows.ReadConsoleInput(new IntPtr(Windows.GetStdHandle((int)StdHandles.STD_INPUT_HANDLE)), InRec, 1, out EventCount);
                if (EventCount == 0)
                {
                    return;
                }
                switch ((EventTypes)InRec[0].EventType)
                {
                case EventTypes.KEY_EVENT:
                    if (SysKeyCount <= SysKeyQue.GetUpperBound(0))
                    {
                        if (InRec[0].KeyEvent.bKeyDown)
                        {
                            SysKeyQue[SysKeyCount].wKeyEvent = InRec[0].KeyEvent;
                            SysShiftState = SysKeyQue[SysKeyCount].skeShiftState;
                            switch ((int)InRec[0].KeyEvent.wVirtualKeyCode)
                            {
                            case VK_SHIFT:
                            case VK_CONTROL:
                            case VK_MENU:
                                break;

                            default:
                                System.Text.Encoding enc = System.Text.Encoding.GetEncoding(866);
                                byte[] bb = enc.GetBytes(new char[] { InRec[0].KeyEvent.UnicodeChar });
                                SysKeyQue[SysKeyCount].skeKeyCode = TranslateKeyCode((byte)InRec[0].KeyEvent.wVirtualKeyCode, (byte)InRec[0].KeyEvent.wVirtualScanCode, /*InRec.KeyEvent.AsciiChar*/ bb[0], InRec[0].KeyEvent.dwControlKeyState);
                                SysKeyQue[SysKeyCount].wKeyEvent  = InRec[0].KeyEvent;
                                if (SysKeyQue[SysKeyCount].skeKeyCode == 0)
                                {
                                    return;
                                }
                                FoundAlt = false;
                                if (((SysKeyQue[SysKeyCount].skeShiftState & 0x08) == 0x08) &&
                                    ((InRec[0].KeyEvent.dwControlKeyState & 0x100) == 0))
                                {
                                    if (SysPlatform == 1)
                                    {
                                        for (int i = 0; i < 10; i++)
                                        {
                                            if (SysKeyQue[SysKeyCount].skeKeyCode == AltNumericKeys[i].VK)
                                            {
                                                AltNumeric = (byte)((AltNumeric * 10) + AltNumericKeys[i].Value);
                                                FoundAlt   = true;
                                            }
                                        }
                                    }
                                    else
                                    if (((int)InRec[0].KeyEvent.wVirtualKeyCode >= VK_NUMPAD0) && ((int)InRec[0].KeyEvent.wVirtualKeyCode <= VK_NUMPAD9))
                                    {
                                        AltNumeric = (byte)((AltNumeric * 10) + InRec[0].KeyEvent.wVirtualKeyCode - VK_NUMPAD0);
                                        FoundAlt   = true;
                                    }
                                }
                                if (!FoundAlt)
                                {
                                    SysKeyCount++;
                                    AltNumeric = 0;
                                }
                                break;
                            }
                        }
                        else
                        {
                            if ((int)InRec[0].KeyEvent.wVirtualKeyCode == VK_MENU)
                            {
                                if (AltNumeric != 0)
                                {
                                    SysKeyQue[SysKeyCount].skeKeyCode = AltNumeric;
                                    AltNumeric = 0;
                                    SysKeyCount++;
                                }
                            }
                        }
                    }
                    break;

                case EventTypes.MOUSE_EVENT:
                    if (SysMouCount <= SysMouQue.GetUpperBound(0))
                    {
                        SysMouQue[SysMouCount].smePos.X   = InRec[0].MouseEvent.dwMousePosition.X;
                        SysMouQue[SysMouCount].smePos.Y   = InRec[0].MouseEvent.dwMousePosition.Y;
                        SysMouQue[SysMouCount].smeButtons = (byte)InRec[0].MouseEvent.dwButtonState;
                        SysMouQue[SysMouCount].smeTime    = (int)SysSysMouseCount();
                        SysMouCount++;
                    }
                    break;
                }
            } while (true && (SysKeyCount <= SysKeyQue.GetUpperBound(0)));
        }