Created
February 25, 2017 04:32
-
-
Save twinkfrag/89df2aacf21465bad0c2bd4b5bd20ba7 to your computer and use it in GitHub Desktop.
Translate Scancode and VirtualKeyCode each other
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Runtime.InteropServices; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace KeyCode | |
{ | |
// MapVirtualKey Function | |
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms646306.aspx | |
// | |
// Virtual-Key Codes | |
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx | |
// | |
// Scan Codes | |
// http://yanor.net/wiki/?Windows%2FTIPS%2F%E3%83%AC%E3%82%B8%E3%82%B9%E3%83%88%E3%83%AA%E3%82%92%E4%BF%AE%E6%AD%A3%E3%81%97%E3%81%A6CAPSLOCK%E3%81%AE%E5%89%B2%E3%82%8A%E5%BD%93%E3%81%A6%E5%A4%89%E6%9B%B4 | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine(MapVirtualKey(VK.F13, MAPVK.VK_TO_VSC).ToString("X4")); | |
Console.WriteLine(MapVirtualKey(VSC.F13, MAPVK.VSC_TO_VK).ToString("X4")); | |
} | |
[DllImport("User32.dll")] | |
static extern uint MapVirtualKey(VK uCode, MAPVK uMapType); | |
[DllImport("User32.dll")] | |
static extern uint MapVirtualKey(VSC uCode, MAPVK uMapType); | |
} | |
enum MAPVK : uint | |
{ | |
VK_TO_CHAR = 2, | |
VK_TO_VSC = 0, | |
VSC_TO_VK = 1, | |
VSC_TO_VK_EX = 3 | |
} | |
enum VK : uint | |
{ | |
MBUTTON = 0x04, | |
F13 = 0x7C, | |
} | |
enum VSC : uint | |
{ | |
NULL = 0x00, | |
F13 = 0x64, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment