⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboard.h

📁 VC++ DEMO, used for the beginners and the amour
💻 H
字号:

#ifndef KEYBOARD_H
#define KEYBOARD_H

class Key_Event
{
public:
	virtual void ProcessEvent() = 0;
};

class Key
{
public:
	Key(unsigned char ScanCode = 0, ISModifierState Modifier = kismsNone) 
		: m_TimeStamp(0), m_ScanCode(ScanCode), m_Modifier(Modifier)
	{}
	
	Key & operator= (const Key & Key)
	{
		m_Modifier  = Key.m_Modifier;
		m_ScanCode  = Key.m_ScanCode;
		m_TimeStamp = Key.m_TimeStamp;
		return *this;
	}

	inline bool	           operator== (const Key & That) const
	{ 
		return ((m_Modifier == That.m_Modifier) && 
				(m_ScanCode == That.m_ScanCode)); 
	}

	inline bool				operator< (const Key & That) const
	{ 
		unsigned short First	 = Pack();
		unsigned short Second = That.Pack();
		return (First < Second); 
	}

	inline unsigned short	Pack(void) const
	{
		unsigned short theResult;
		theResult = m_Modifier;
		theResult = theResult << 8;
		theResult = theResult | m_ScanCode;
		return theResult;
	}

	unsigned long					m_TimeStamp;
	ISModifierState			        m_Modifier;
	unsigned char					m_ScanCode;
};

class Hot_Key
{
public:
	Hot_Key( const string&	Name,
		const Key &	DefaultKey,
		Key_Event*		JustPressedEvent	= NULL,
		Key_Event*		PressedEvent		= NULL,
		Key_Event*		JustUnPressedEvent	= NULL)
	{
		m_Name = Name;
		m_Key = DefaultKey;
		m_JustPressedEvent = JustPressedEvent;
		m_PressedEvent = PressedEvent;
		m_JustUnPressedEvent = JustUnPressedEvent;
	}
	inline void	FirePressedEvent(void)
	{ if (m_PressedEvent) m_PressedEvent->ProcessEvent(); }
	inline void	FireJustPressedEvent(void)
	{ if (m_JustPressedEvent) m_JustPressedEvent->ProcessEvent(); }
	inline void	FireJustUnPressedEvent(void)
	{ if (m_JustUnPressedEvent) m_JustUnPressedEvent->ProcessEvent(); }
	
	string					m_Name;					/* the unique name of this hotkey */
	Key     				m_Key;					/* the key and modifier */
	Key_Event*				m_JustPressedEvent;		/* the event to fire when the hotkey is just pressed */
	Key_Event*				m_PressedEvent;			/* the event to fire when the hotkey is being pressed */
	Key_Event*				m_JustUnPressedEvent;	/* the event to fire when the hotkey is released */
};
typedef vector<Key> KeyVector_t;
#endif

⌨️ 快捷键说明

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