keyboard.h

来自「Visual C++ 游戏开发与设计实例 源代码(所有)」· C头文件 代码 · 共 59 行

H
59
字号
/*******************************************************************
 *         Advanced 3D Game Programming using DirectX 7.0
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   Title: Keyboard.h
 *    Desc: Wrapper of a DirectInput keyboard object
 *          
 * copyright (c) 1999 by Adrian Perez
 * See license.txt for modification and distribution information
 ******************************************************************/

#ifndef _KEYBOARD_H
#define _KEYBOARD_H

#include <memory.h>
#include <dinput.h>

class cInputLayer;

/**
 * Any object that implements this interface can receive input
 * from the keyboard.
 */
struct iKeyboardReceiver
{
	virtual void KeyUp( int key ){};
	virtual void KeyDown( int key ){};
};


class cKeyboard  
{

	LPDIRECTINPUTDEVICE8	m_pDevice; // The Direct Input Device that represents the keyboard

	char					m_keyState[256];

	iKeyboardReceiver*		m_pTarget;

public:

	void ClearTable()
	{
		memset( m_keyState, 0, sizeof(char)*256 );
	}

	cKeyboard( HWND hWnd );
	~cKeyboard();

	// Poll to see if a certain key is down
	bool Poll( int key );

	// Use this to establish a KeyboardReceiver as the current input focus
	void SetReceiver( iKeyboardReceiver* pTarget );

	eResult Update();
};

#endif //_KEYBOARD_H

⌨️ 快捷键说明

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