Game Development Community

T3D 1.2 - don't stop key trigger when lost focus on fullscreen + fix

by Mquaker · in Torque 3D Professional · 04/02/2012 (9:07 pm) · 0 replies

Thread Titles:
player moving and weapon firing key trigger event does not stop when lost application focus.

Platform:
Windows XP x86 / Windows 7 x64

Steps to Repeat:
1. change fullscreen mode your game.
2. press win key or alt+tab when input move or fire or jump key.

Steps to Repeat:

open '_dispatch()' function in 'windowManager/win32/winDispatch.cpp'.
and find below case.
case WM_ACTIVATEAPP:
		if (wParam) 
		{
			// Could extract current modifier state from windows.
			_ModifierKeys = 0;
			Input::setModifierKeys(_ModifierKeys);
		}

replace to this.
case WM_ACTIVATEAPP:

		// clear any key states 
		_ModifierKeys = 0;
		dMemset(keyboardState, 0, 256);
		Input::setModifierKeys(0);

		if (wParam)
		{
			if (cursorVisible == false)
				window->setCursorVisible(false);

			if (cursorLocked == true)
				window->setMouseLocked(true);

			// Update window state.
			window->setBackground(false);

			// Fire event.
			window->appEvent.trigger(devId, GainFocus);

			if (!Input::isActive())
				Input::activate();
		}
		else
		{
			HWND hwnd = (HWND)wParam;
			UTF16 classBuf[256];

			if (hwnd)
				GetClassName(hwnd, classBuf, sizeof(classBuf));

			// We toggle the mouse lock when we become inactive 
			// causing the subsequent lock call to defer itself
			// until the window becomes active again.
			if (window && window->isMouseLocked())
			{
				window->setMouseLocked( false );
				window->setMouseLocked( true );
			}

			// FIXME [tom, 5/1/2007] Hard coding this is lame since there's a const in win32Window.cpp
			// CodeReview - this fails if there is a second jug app in the arena.
			if (hwnd == NULL || dStrcmp(classBuf, L"TorqueJuggernaughtWindow") != 0)
			{
				// We are being made inactive and the window being made active isn't
				// a jugg window. Thus, we need to deactivate input.
				if (Input::isActive())
					Input::deactivate();
			}

			cursorVisible = window->isCursorVisible();
			if (!cursorVisible)
				window->setCursorVisible(true);

			cursorLocked = window->isMouseLocked();
			if (cursorLocked)
				window->setMouseLocked(false);

			// Update window state.
			window->setBackground(true);

			// Fire event.
			window->appEvent.trigger(devId, LoseFocus);
		}

i manually set key focus process from 'WM_SETFOCUS' and 'WM_KILLFOCUS'.

ps. this problem appear only fullscreen, not appear windowd mode.