Esempio n. 1
0
	/// @brief Add a key for the specified action.
	/// 
	/// @param _sKey Input key (need to be a valid key).
	/// @param _sAction Action name.
	void CActionMap::AddKey(const String &_sKey, const String &_sAction)
	{
		EKey eKey = GetKeyFromString(_sKey);
		if(eKey < K_Nb)
		{
			// Get the action
			SAction *pAction = GetAction(_sAction);
			if(pAction != 0)
				m_aActionMap.insert(ActionMap::value_type(eKey, pAction));
		}		
		else
            SamLogWarning("Unable to find key '%s' for the action '%s'", _sKey, _sAction);
	}
Esempio n. 2
0
	/// @brief Initialize the device.
	/// 
	/// @return true if no error occurred.
	bool CKeyboard::Init()
	{
		SAM_ASSERT(m_pKeyboard == NULL, "Keyboard is already initialized");

		// create device
		HRESULT hResult = g_Env->pInputManager->GetInputSystem()->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, NULL);
		if(FAILED(hResult))
		{
			SamLogWarning("Unable to create keyboard device, error code: %d\n", hResult);
			return false;
		}

		hResult = m_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
		if(FAILED(hResult))
		{
			SamLogError("Unable to set data format for keyboard device, error code: %d\n", hResult);
			return false;
		}

#ifdef ENABLE_BUFFER_MODE
		// Enable buffered mode.
		DIPROPDWORD oProperty;
		oProperty.diph.dwSize = sizeof(DIPROPDWORD);
		oProperty.diph.dwHeaderSize = sizeof(DIPROPHEADER);
		oProperty.diph.dwObj = 0;
		oProperty.diph.dwHow = DIPH_DEVICE;
		oProperty.dwData = KEY_BUFFERSIZE;

		hResult = m_pKeyboard->SetProperty(DIPROP_BUFFERSIZE, &oProperty.diph);
		if(FAILED(hResult))
		{
			SamLogError("Unable to set buffered mode for keyboard device, error code: %d\n", hResult);
			return false;
		}
#endif

		// Exclusive by default.
		if(!SetExclusiveMode(false))
			return false;

		// Enable the device.
		if(!Enable(true))
			return false;

		return true;
	}
Esempio n. 3
0
	/// @brief Exclusive mode.
	/// 
	/// @param _bExclusive True to active exclusive mode.
	/// 
	/// @return True if no error occurred.
	bool CKeyboard::SetExclusiveMode(bool _bExclusive)
	{
		SAM_ASSERT(m_pKeyboard != NULL, "Keyboard was not initialized");

		int nFlags = DISCL_FOREGROUND;
		if(_bExclusive)
			nFlags |= DISCL_EXCLUSIVE;
		else
			nFlags |= DISCL_NONEXCLUSIVE | DISCL_NOWINKEY;

		HRESULT hResult = m_pKeyboard->SetCooperativeLevel(g_Env->pInputManager->GetHWND(), nFlags);
		if(FAILED(hResult))
		{
			SamLogWarning("Unable to set exclusive mode for keyboard device, error code: %d", hResult);
			return false;
		}

		return true;
	}
Esempio n. 4
0
	/// @brief Enable the device.
	/// 
	/// @param _bEnable True to enable the device.
	/// 
	/// @return True if no error occurred.
	bool CKeyboard::Enable(bool _bEnable)
	{
		SAM_ASSERT(m_pKeyboard != NULL, "Keyboard was not initialized");

		m_bEnabled = _bEnable;

		HRESULT hResult = S_OK;
		if(_bEnable)
			hResult = m_pKeyboard->Acquire();
		else
			hResult = m_pKeyboard->Unacquire();

		if(FAILED(hResult))
		{
			SamLogWarning("Unable to enable the keyboard device, error code: %d", hResult);
			return false;
		}
		
		return true;
	}