im working on a remote desk protocol and need to share the keyboard input. im just starting but i know i will meet a lot of troubles later when needing to share shortcuts like ctrl+c, alt+tab etc…
thats my code for now.(the casting of the keys and the positioning of the mouse is just for debugging, ill later modify it to use threads and other features)
std::unordered_map<int, std::string> keyMap =
{
{0x01, "Left mouse button"},
{0x02, "Right mouse button"},
{0x03, "Control-break processing"},
{0x04, "Middle mouse button"},
{0x05, "X1 mouse button"},
{0x06, "X2 mouse button"},
{0x08, "BACKSPACE"},
{0x09, "TAB"},
{0x0C, "CLEAR"},
{0x0D, "ENTER"},
{0x10, "SHIFT"},
{0x11, "CTRL"},
{0x12, "ALT"},
{0x13, "PAUSE"},
{0x14, "CAPS LOCK"},
{0x15, "IME Kana mode"},
{0x17, "IME Junja mode"},
{0x18, "IME final mode"},
{0x19, "IME Hanja mode"},
{0x1B, "ESCAPE"},
{0x1C, "IME convert"},
{0x1D, "IME nonconvert"},
{0x1E, "IME accept"},
{0x1F, "IME mode change request"},
{0x20, "SPACE"},
{0x21, "PAGE UP"},
{0x22, "PAGE DOWN"},
{0x23, "END"},
{0x24, "HOME"},
{0x25, "LEFT ARROW"},
{0x26, "UP ARROW"},
{0x27, "RIGHT ARROW"},
{0x28, "DOWN ARROW"},
{0x29, "SELECT"},
{0x2A, "PRINT"},
{0x2B, "EXECUTE"},
{0x2C, "PRINT SCREEN"},
{0x2D, "INS"},
{0x2E, "DEL"},
{0x2F, "HELP"},
{0x30, "0"},
{0x31, "1"},
{0x32, "2"},
{0x33, "3"},
{0x34, "4"},
{0x35, "5"},
{0x36, "6"},
{0x37, "7"},
{0x38, "8"},
{0x39, "9"},
{0x41, "A"},
{0x42, "B"},
{0x43, "C"},
{0x44, "D"},
{0x45, "E"},
{0x46, "F"},
{0x47, "G"},
{0x48, "H"},
{0x49, "I"},
{0x4A, "J"},
{0x4B, "K"},
{0x4C, "L"},
{0x4D, "M"},
{0x4E, "N"},
{0x4F, "O"},
{0x50, "P"},
{0x51, "Q"},
{0x52, "R"},
{0x53, "S"},
{0x54, "T"},
{0x55, "U"},
{0x56, "V"},
{0x57, "W"},
{0x58, "X"},
{0x59, "Y"},
{0x5A, "Z"},
{0x5B, "Left Windows key"},
{0x5C, "Right Windows key"},
{0x5D, "Applications key"},
{0x5F, "Computer Sleep key"},
{0x60, "Numeric keypad 0"},
{0x61, "Numeric keypad 1"},
{0x62, "Numeric keypad 2"},
{0x63, "Numeric keypad 3"},
{0x64, "Numeric keypad 4"},
{0x65, "Numeric keypad 5"},
{0x66, "Numeric keypad 6"},
{0x67, "Numeric keypad 7"},
{0x68, "Numeric keypad 8"},
{0x69, "Numeric keypad 9"},
{0x6A, "Multiply"},
{0x6B, "Add"},
{0x6C, "Separator"},
{0x6D, "Subtract"},
{0x6E, "Decimal"},
{0x6F, "Divide"},
{0x70, "F1"},
{0x71, "F2"},
{0x72, "F3"},
{0x73, "F4"},
{0x74, "F5"},
{0x75, "F6"},
{0x76, "F7"},
{0x77, "F8"},
{0x78, "F9"},
{0x79, "F10"},
{0x7A, "F11"},
{0x7B, "F12"},
{0x7C, "F13"},
{0x7D, "F14"},
{0x7E, "F15"},
{0x7F, "F16"},
{0x80, "F17"},
{0x81, "F18"},
{0x82, "F19"},
{0x83, "F20"},
{0x84, "F21"},
{0x85, "F22"},
{0x86, "F23"},
{0x87, "F24"},
{0x90, "NUM LOCK"},
{0x91, "SCROLL LOCK"},
{0xA0, "Left SHIFT"},
{0xA1, "Right SHIFT"},
{0xA2, "Left CONTROL"},
{0xA3, "Right CONTROL"},
{0xA4, "Left MENU"},
{0xA5, "Right MENU"},
{0xA6, "Browser Back"},
{0xA7, "Browser Forward"},
{0xA8, "Browser Refresh"},
{0xA9, "Browser Stop"},
{0xAA, "Browser Search"},
{0xAB, "Browser Favorites"},
{0xAC, "Browser Home"},
{0xAD, "Volume Mute"},
{0xAE, "Volume Down"},
{0xAF, "Volume Up"},
{0xB0, "Next Track"},
{0xB1, "Previous Track"},
{0xB2, "Stop Media"},
{0xB3, "Play/Pause Media"},
{0xB4, "Start Mail"},
{0xB5, "Select Media"},
{0xB6, "Start Application 1"},
{0xB7, "Start Application 2"},
{0xBA, "Used for miscellaneous characters; it can vary by keyboard."},
{0xBB, "For any country/region, the '+' key"},
{0xBC, "For any country/region, the ',' key"},
{0xBD, "For any country/region, the '-' key"},
{0xBE, "For any country/region, the '.' key"},
{0xBF, "Used for miscellaneous characters; it can vary by keyboard."},
{0xC0, "Used for miscellaneous characters; it can vary by keyboard."},
{0xDB, "Used for miscellaneous characters; it can vary by keyboard."},
{0xDC, "Used for miscellaneous characters; it can vary by keyboard."},
{0xDD, "Used for miscellaneous characters; it can vary by keyboard."},
{0xDE, "Used for miscellaneous characters; it can vary by keyboard."},
{0xDF, "Used for miscellaneous characters; it can vary by keyboard."},
{0xE5, "IME PROCESS key"},
{0xF6, "Attn key"},
{0xF7, "CrSel key"},
{0xF8, "ExSel key"},
{0xF9, "Erase EOF key"},
{0xFA, "Play key"},
{0xFB, "Zoom key"},
{0xFC, "Reserved"},
{0xFD, "PA1 key"},
{0xFE, "Clear key"}
};
bool keyStates[255] = { false };
while (true)
{
for (int i = 0; i < 255; ++i)
{
SHORT keyState = GetAsyncKeyState(i);
bool isPressed = keyState & 0x8000;
if ((isPressed && !keyStates[i]) || (isPressed && keyStates[i]))
{
std::cout << "Key " << keyMap[i] << " is pressed." << std::endl;
keyStates[i] = true;
}
else if (!isPressed && keyStates[i])
{
keyStates[i] = false;
}
if (isPressed && keyMap[i] == "A")//used for getting the mouses position
{
POINT p;
if (!GetCursorPos(&p))
{
std::cout << GetLastError() << std::endl;
}
else
{
std::cout << std::endl << "X is: " << p.x << std::endl << "Y is: " << p.y << std::endl << std::endl;
}
}
}
Sleep(50);
}
i tried looking around the internet for answers but couldnt really find smthing. if my way of solving it is wrong and there is a better way please say so.
thx
1