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

📄 input.h

📁 3D游戏展示程序
💻 H
字号:
//--------------------------------------------------
//  Desc: DirectInput8 Interface
//  Date: 2006.8.8 /update
//  Author: artsylee
//
//  Copyright (C) 2006 artsylee
//
//  Update: 2006.8.18 add CInputDevice class
//			stInputInfo结构添加mouse是否移动信息(2006_11_15)
//			从MouseState中获取鼠标移动信息(2007_3_26)
//--------------------------------------------------

#ifndef _INPUT_
#define _INPUT_

#define DIRECTINPUT_VERSION 0x0800

#include <dinput.h>
#pragma comment(lib, "dinput8.lib")
#pragma comment(lib, "dxguid.lib")

#define BUFFERSIZE			32
#define MAXKEY				256
#define MOUSEBUTTON			4

#define KEYDOWN(name, key) (name[key] & 0x80)

struct stInputInfo
{
	POINT			point;        // point of mouse in window client
	unsigned int	KeyValue;     // key value in buffered mode
	unsigned int	MouseValue;   // mouse value in buffered mode
	bool			MouseMove;    // 相对于上一帧mouse是否移动(2006_11_15).		
};

//----------------------------------------
//----------------------------------------
// virtual input device
//----------------------------------------
//----------------------------------------
class ASE_DLL CInputDevice
{
public:
	CInputDevice();
	virtual ~CInputDevice();

	virtual BOOL CreateDevice(HWND hWnd) = 0;
	virtual void ReleaseDevice(void) = 0;

	virtual HRESULT GetState(void) = 0;
	virtual HRESULT GetData(void) = 0;

	virtual bool IsKeyDown(unsigned char key) = 0;

	virtual void SetBufferKey(unsigned int key, bool bKeyDown = true) = 0;
	unsigned int GetBufferKey(void);
	void ClearBufferKey(void);
protected:
	LPDIRECTINPUTDEVICE8   m_lpDevice;

	// Use unsigned int to hold key buffer data
	unsigned int m_BufferData[BUFFERSIZE];
	int          m_BufferStart;
	int			 m_BufferEnd;
};

//----------------------------------------
//----------------------------------------
// CKey class
//----------------------------------------
//----------------------------------------
class ASE_DLL CKey : public CInputDevice
{
public:
	CKey();
	virtual ~CKey();
public:
	virtual BOOL CreateDevice(HWND hWnd);
	virtual void ReleaseDevice(void);

	virtual HRESULT GetState(void);
	virtual HRESULT GetData(void);

	virtual bool IsKeyDown(unsigned char key);
	virtual void SetBufferKey(unsigned int key, bool bKeyDown = true);
	// Set key down

private:
	// Immediate Data
	unsigned char m_KeyState[MAXKEY];
};

//----------------------------------------
//----------------------------------------
// CMouse class
//----------------------------------------
//----------------------------------------
#define LB_DOWN		1
#define RB_DOWN		2
#define MB_DOWN		4
#define LB_UP		8
#define RB_UP		16
#define MB_UP		32

enum BTN_MOUSE
{
	LBUTTON		= 0,
	RBUTTON		= 1,
	MBUTTON		= 2,
	LRBUTTON	= 3,
};

class ASE_DLL CMouse : public CInputDevice
{
public:
	CMouse();
	virtual ~CMouse();
public:
	virtual BOOL CreateDevice(HWND hWnd);
	virtual void ReleaseDevice(void);

	virtual HRESULT GetState(void);
	virtual HRESULT GetData(void);

	virtual bool IsKeyDown(unsigned char mouse);
	virtual void SetBufferKey(unsigned int key, bool bKeyDown = true);

	void GetPointerOffset(long *x, long *y, long *z);

private:
	// Immediate Data
	long  m_XPos;
	long  m_YPos;
	long  m_ZPos;
	DWORD MouseButton[MOUSEBUTTON];
};

//----------------------------------------
//----------------------------------------
// CInput class
//----------------------------------------
//----------------------------------------
class ASE_DLL CInput
{
public:
	CInput();
	~CInput();

	BOOL CreateInput(HWND hWnd);
	void ReleaseInput(void);	

	CKey *GetKeyPtr(void)     {  return &m_Key;   }
	CMouse *GetMousePtr(void) {  return &m_Mouse; }

	BOOL UpdateBufferInput(stInputInfo *input);
	
private:
	CKey		m_Key;
	CMouse		m_Mouse;

	HWND		m_hWnd;
	POINT		m_OldPt;
};



#endif // _INPUT_

⌨️ 快捷键说明

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