예제 #1
0
        public static string ConvertKeyToString(Keys vKey)
        {
            if (vKey >= Keys.F1 && vKey <= Keys.F12)
            {
                return(vKey.ToString());
            }

            byte[] keyboardState       = new byte[255];
            bool   keyboardStateStatus = WindowApi.GetKeyboardState(keyboardState);

            if (!keyboardStateStatus)
            {
                return("");
            }

            uint   virtualKeyCode        = (uint)vKey;
            uint   scanCode              = WindowApi.MapVirtualKey(virtualKeyCode, 0);
            IntPtr inputLocaleIdentifier = WindowApi.GetKeyboardLayout(0);

            StringBuilder result = new StringBuilder();

            WindowApi.ToUnicodeEx(virtualKeyCode, scanCode, keyboardState, result, (int)5, (uint)0, inputLocaleIdentifier);

            return(result.ToString().ToUpper());
        }