keyboardmgr_t.cpp

来自「VC++ DEMO, used for the beginners and th」· C++ 代码 · 共 73 行

CPP
73
字号
// KeyboardMgr_t.cpp: implementation of the KeyboardMgr_t class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "KeyboardMgr_t.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

KeyboardMgr_t::KeyboardMgr_t()
{
	m_KeyboardMap.clear();
}

KeyboardMgr_t::~KeyboardMgr_t()
{
	KeyboardMap_t::iterator	theIterator;

	for (theIterator = m_KeyboardMap.begin(); theIterator != m_KeyboardMap.end(); theIterator++)
	{
		delete (*theIterator).second;
		(*theIterator).second = NULL;
	}
	m_KeyboardMap.clear();
}

void KeyboardMgr_t::SetKeyboardMap(Hot_Key * HotKey)
{
	if ( m_KeyboardMap.find(HotKey->m_Key) == m_KeyboardMap.end() )
	{
		m_KeyboardMap[HotKey->m_Key]= HotKey;
	}
}

void KeyboardMgr_t::FireEvent(const KeyVector_t& JustPressedKeys,const KeyVector_t& PressedKeys,
							  const KeyVector_t& JustUnPressedKeys)
{
	KeyboardMap_t::iterator	theHotKeyIterator;
	KeyVector_t::const_iterator	theKeyIterator;
	/* loop through the just pressed keys */
	for (theKeyIterator = JustPressedKeys.begin(); theKeyIterator != JustPressedKeys.end(); theKeyIterator++)
	{
	/* this is a fast lookup since it is a map.  if we find a hotkey for the
		* key press, fire the event. */
		theHotKeyIterator = m_KeyboardMap.find((*theKeyIterator));
		if (theHotKeyIterator != m_KeyboardMap.end())
			(*theHotKeyIterator).second->FireJustPressedEvent();
	}
	
	/* loop through the pressed keys */
	for (theKeyIterator = PressedKeys.begin(); theKeyIterator != PressedKeys.end(); theKeyIterator++)
	{
	/* this is a fast lookup since it is a map.  if we find a hotkey for the
		* key press, fire the event. */
		theHotKeyIterator = this->m_KeyboardMap.find((*theKeyIterator));
		if (theHotKeyIterator != this->m_KeyboardMap.end())
			(*theHotKeyIterator).second->FirePressedEvent();
	}
	
	/* loop through the just unpressed keys */
	for (theKeyIterator = JustUnPressedKeys.begin(); theKeyIterator != JustUnPressedKeys.end(); theKeyIterator++)
	{
	/* this is a fast lookup since it is a map.  if we find a hotkey for the
		* key press, fire the event. */
		theHotKeyIterator = this->m_KeyboardMap.find((*theKeyIterator));
		if (theHotKeyIterator != this->m_KeyboardMap.end())
			(*theHotKeyIterator).second->FireJustUnPressedEvent();
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?