47 if (FAILED(hr =
g_pKeyboard->SetDataFormat(&c_dfDIKeyboard)))
56 if (FAILED(hr =
g_pKeyboard->SetCooperativeLevel(NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)))
72 hkl = GetKeyboardLayout(0);
76 #pragma region Startup Commands 78 command.
name =
"SetNumLockState";
89 if (std::find(
hwnds.begin(),
hwnds.end(), GetForegroundWindow()) !=
hwnds.end())
114 for (UINT i = 0; i < 256; i++)
116 if (i == DIK_LMENU || i == DIK_RMENU)
120 if (i == DIK_LCONTROL || i == DIK_RCONTROL)
124 if (i == DIK_LSHIFT || i == DIK_RSHIFT)
128 if (i == DIK_CAPSLOCK)
132 if (i == DIK_NUMLOCK)
147 sprintf_s(msg, 99,
"Keyboard::FrameMove Keypress %i adding commands!", i);
154 UINT vk = MapVirtualKeyEx(i, MAPVK_VSC_TO_VK,
hkl);
169 sprintf_s(msg, 99,
"Keyboard::FrameMove Could not translate scancode %i into a VK", i);
185 if (vk == VK_BACK && strlen(
buffer) > 0)
192 char charBuffer[2] = {
static_cast<char>(MapVirtualKeyEx(vk, MAPVK_VK_TO_CHAR,
hkl)), 0};
206 if (LOWORD(GetKeyState(VK_NUMLOCK)) != 0)
260 sprintf_s(boo, 99,
"Keyboard::FrameMove Unhandled SC %i (VK %02x) ctrl%i alt%i shift%i", i, vk,
ctrl,
alt,
shift);
274 if (command.
delay != 0.0f)
continue;
276 if (command.
name ==
"SetNumLockState")
286 bool curState = LOWORD(GetKeyState(VK_NUMLOCK)) != 0;
287 if (curState != setState)
290 keybd_event(VK_NUMLOCK, DIK_NUMLOCK, KEYEVENTF_EXTENDEDKEY | 0, 0);
293 keybd_event(VK_NUMLOCK, DIK_NUMLOCK, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
307 sprintf_s(msg, 199,
"Keyboard::EnumKeyboardsCallback {%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}",
308 pdidInstance->guidInstance.Data1, pdidInstance->guidInstance.Data2, pdidInstance->guidInstance.Data3,
309 pdidInstance->guidInstance.Data4[0], pdidInstance->guidInstance.Data4[1], pdidInstance->guidInstance.Data4[2], pdidInstance->guidInstance.Data4[3],
310 pdidInstance->guidInstance.Data4[4], pdidInstance->guidInstance.Data4[5], pdidInstance->guidInstance.Data4[6], pdidInstance->guidInstance.Data4[7]);
317 return DIENUM_CONTINUE;
LPDIRECTINPUTDEVICE8 g_pKeyboard
void BufferProc(bool bEnterKey)
unsigned char keyboardState[256]
contains state of keyboard
static BOOL CALLBACK EnumKeyboardsCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
std::vector< Command > commandStream
void AppendCommands(std::vector< Command > *commands)
okay, the portable keyboard numbers don't work like the outside keypad because the outside keypad is ...
void FrameMove(float fElapsed)
std::string name
command name
static void SetNumLock(bool bState)
KeyboardConfig * keyboardConfig
unsigned char oldKeyboardState[256]
contains previous state of keyboard
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
void Initialize(Logger *logger, KeyboardConfig *config, Bus *prmBus, LPDIRECTINPUT8 g_pDI)
std::vector< Buffer > buffers
float delay
wait number of seconds before executing command
std::vector< HWND > hwnds
float timeSinceLastKeypress
Devices::Keyboard keyboard