Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: "keyPressed" called twice when toggling fullscreen  (Read 1325 times)

DanielH

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 3
    • View Profile
"keyPressed" called twice when toggling fullscreen
« on: January 18, 2007, 08:51:49 AM »

Hello,

For some reason which I can't figure out my keyPressed function is called twice when I toggle fullscreen mode.

I'm using this code:

Code: [Select]

bool Game::keyPressed(const OIS::KeyEvent& arg)
{
if (arg.key == OIS::KC_RETURN && m_keyboard->isModifierDown(OIS::Keyboard::Alt))
m_renderer->ToggleFullscreen();

if (arg.key == OIS::KC_ESCAPE)
RequestShutdown();

return true;
}


Do I have to recreate my keyboard or something when the window is resized? Or can I just reset the input somehow so that the keys no longer exists in the buffer?
Logged

DanielH

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 3
    • View Profile
"keyPressed" called twice when toggling fullscreen
« Reply #1 on: January 18, 2007, 09:04:07 AM »

Hehe just after I had made that post I read the DirectX manual and found this snippet for flushing:

Code: [Select]

dwItems = INFINITE;
hres = idirectinputdevice9_GetDeviceData(
            pdid,
            sizeof(DIDEVICEOBJECTDATA),
            NULL,
            &dwItems,
            0);
if (SUCCEEDED(hres)) {
    // Buffer successfully flushed.
    // dwItems = Number of elements flushed.
    if (hres == DI_BUFFEROVERFLOW) {
        // Buffer had overflowed.
    }
}


I made a new flush function in the keyboard class and now it works great if I flush before toggle fullscreen mode! :)
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
"keyPressed" called twice when toggling fullscreen
« Reply #2 on: January 18, 2007, 09:07:37 AM »

Hmm, I don't really know why you need to flush anything :? Are you using Ogre, and if so, how are you toggling full screen?

What key(s) are being repeated?

It would possibly be possibly to add a flush method to the keyboard classes, but I would like to understand what you are seeing more before I add something perhaps unneccessarily.
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
"keyPressed" called twice when toggling fullscreen
« Reply #3 on: January 18, 2007, 09:12:58 AM »

If it is the Alt key that is being duplicated, you should try a different key combination - maybe just a simple "F11" key, as a few apps use that to signal fullscreen.

Alt can have some issues if you are not using Ogre Eihort, you should listen for the WM_SYS (iirc) message in your winproc and return true when it comes.
Logged

DanielH

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 3
    • View Profile
"keyPressed" called twice when toggling fullscreen
« Reply #4 on: January 18, 2007, 10:59:58 AM »

I tried commenting away the flush and re-compiled. Oddly enought it worked like it supposed to then, but it seems to me I can't trust it really =)... I'm currently investigating my Win32Window code to see if there is anything odd that can relate to this problem.

My ToggleFullscreen is basically a call to the windows SetFullscreen function and then a reset on the Direct3D device - this is my own engine.

My windows fullscreen-switching code is (not sure what good it will do to post it here, but I do it anyway :D):

Code: [Select]

void Win32Window::SetFullscreen(bool fullscreen)
{
if (fullscreen && !m_fullscreen)
{
::GetWindowRect(m_handle, &m_normalRect);

m_exStyle = WS_EX_APPWINDOW;
m_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP;

::SetWindowLongPtr(m_handle, GWL_EXSTYLE, m_exStyle);
::SetWindowLongPtr(m_handle, GWL_STYLE, m_style);

HWND desktop = ::GetDesktopWindow();
RECT desktopRect;
::GetWindowRect(desktop, &desktopRect);

// Called to reflect the updated window styles
::SetWindowPos(m_handle, HWND_TOPMOST, desktopRect.left, desktopRect.top,
desktopRect.right - desktopRect.left, desktopRect.bottom - desktopRect.top, SWP_FRAMECHANGED);
::ShowWindow(m_handle, SW_MAXIMIZE);
m_fullscreen = true;
}
else if (!fullscreen && m_fullscreen)
{
m_exStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
m_style = WS_OVERLAPPEDWINDOW;

if (!m_resizable)
{
m_style &= ~WS_THICKFRAME;
}

::SetWindowLongPtr(m_handle, GWL_EXSTYLE, m_exStyle);
::SetWindowLongPtr(m_handle, GWL_STYLE, m_style);
// Called to reflect the updated window styles
::ShowWindow(m_handle, SW_SHOWDEFAULT);
::SetWindowPos(m_handle, HWND_NOTOPMOST, m_normalRect.left, m_normalRect.top,
m_normalRect.right - m_normalRect.left, m_normalRect.bottom - m_normalRect.top,
SWP_FRAMECHANGED);
m_fullscreen = false;
}

::ShowWindow(m_handle, SW_SHOW);
::SetForegroundWindow(m_handle);
::SetFocus(m_handle);
}
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 2652
    • View Profile
    • http://www.wreckedgames.com
"keyPressed" called twice when toggling fullscreen
« Reply #5 on: January 22, 2007, 11:18:52 AM »

Hmm, yeah I can't really see anything odd. I have used alt-tab extensively with OIS (which causes fullscreen -> minimized -> fullscreen) and havn't seen any issues. Not sure where the problem lays unfortunately.
Logged