예제 #1
0
        /// <summary>
        /// Ask the keyboard if a key is currently down
        /// </summary>
        /// <param name="testKey">The VK_Code to test</param>
        /// <returns>True if it is down, false it it is not or possibly toggled</returns>
        public static bool IsKeyPressed(VK_Code testKey)
        {
            bool  keyPressed = false;
            short result     = (short)GetKeyState(testKey);

            switch (result)
            {
            case 0:
                // Not pressed and not toggled on.
                keyPressed = false;
                break;

            case 1:
                // Not pressed, but toggled on
                keyPressed = false;
                break;

            default:
                // Pressed (and may be toggled on)
                keyPressed = true;
                break;
            }
            return(keyPressed);
        }
예제 #2
0
 private static extern short GetAsyncKeyState(VK_Code vkey);
예제 #3
0
 static extern short GetKeyState(VK_Code nVirtKey);