Reputation: 2272
In my application I have a parent window created using wxWindow and have a child window on which I'm doing my rendering, this window is created using SDL 2.0. So once I will set the SDL window as a child of wxWindow using SetParent call, all the key board events like key press, key release etc. will go to the child window instead of the parent window.
Following is the dummy code:
wxWindow* pParentWindow = new wxWindow();
SDL_Window* pChildWindow = SDL_CreateWindow("Player", 100, 100, nWindowWidth, nWindowHeight, SDL_WINDOW_SHOWN);
SDL_SysWMinfo SysInfo; //Will hold child Window information SDL_GetWindowWMInfo(pChildWindow , &SysInfo);
HWND SDLHandle = SysInfo.info.win.window;
SetParent(SDLHandle, (HWND)pParentWindow);
After this point SDL window become child of wxWindow, now whenever I'll press any key this event will go only to the child (SDL) window. But I required these event in parent window.
So can anyone please let me know how can I get these events either in my parent window (wxWindow) instead of SDL window or propagate it to the parent window.
Note: I'm using wxWidget 2.8 and SDL 2.0.
Upvotes: 0
Views: 505
Reputation: 20615
If all else fails ( i.e. you cannot get SDL and wxWidgets to play nicely ) you might consider hooking the keyboard.
/**
Callback for low level keyboard hook
*/
LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam);
// If key is being pressed
if (wParam == WM_KEYDOWN) {
switch(p->vkCode) {
...
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
// Set windows hook
HHOOK keyboardHook = SetWindowsHookEx(
WH_KEYBOARD_LL,
keyboardHookProc,
GetModuleHandle (0),
//hInstance,
0);
if( ! keyboardHook ) {
printf("Keyboard hook failed\n");
}
Upvotes: 2