?? asl_input.h
字號:
//-----------------------------------------------------------------------------
//
// ____ Azure Star Game Engine 藍星游戲引擎 ____
//
// Copyright (c) 2006, 藍星工作室
// All rights reserved.
//
// 文件名稱: asl_input.h
// 摘 要: 輸入控制類定義
//
// 當(dāng)前版本: 1.0
// 作 者: 湯 祺
// 創(chuàng)建日期: 2006-7-21
//
//-----------------------------------------------------------------------------
#ifndef ASL_INPUT_INCLUDE
#define ASL_INPUT_INCLUDE
#pragma once
#include "asl_utils.h"
#include <queue>
//-----------------------------------------------------------------------------
namespace ASL
{
// 取全局唯一實例
#define INPUT ASLInput::Instance()
// 功能鍵狀態(tài)結(jié)構(gòu)定義
struct ShiftState
{
bool ssCtrl;
bool ssShift;
bool ssAlt;
};
// 鼠標(biāo)按鈕枚舉定義
enum MouseButton
{
mbLeft,
mbRight,
mbMiddle
};
//-----------------------------------------------------------------------------
// ASLInput 輸入控制類定義
// 本類是簡單的輸入控制類, 提供處理鍵盤和鼠標(biāo)輸入的能力. 本類通過定時更新
// 維護一份鍵盤鼠標(biāo)狀態(tài)表. 用戶可以隨時取得當(dāng)前的鍵盤鼠標(biāo)狀態(tài).
//-----------------------------------------------------------------------------
class ASLInput
{
// 常量定義
private:
static const int BUF_SIZE = 256; // 鍵盤緩沖區(qū)大小
// 私有構(gòu)造函數(shù), 析構(gòu)函數(shù). 僅在Instance()函數(shù)中創(chuàng)建
private:
ASLInput(void);
~ASLInput(void);
// 公有函數(shù)
public:
// 取全局唯一實例
static ASLInput& Instance(void);
// 初始化
void Init(HWND hWnd) { m_hWnd = hWnd; }
// 消息處理函數(shù), 需在主窗口的消息處理函數(shù)中調(diào)用
void MsgProc(UINT message, WPARAM wParam, LPARAM lParam);
// 更新函數(shù)
void Update(void);
// 按鍵函數(shù)
public:
// 指定鍵是否剛被按下(相對于上一次調(diào)用Update())
bool IsKeyJustDown(DWORD dwKey)
{ return (m_vKeyState[dwKey] & 0x80) && !(m_vKeyStateOld[dwKey] & 0x80); }
// 指定鍵是否剛被松開(相對于上一次調(diào)用Update())
bool IsKeyJustUp(DWORD dwKey)
{ return !(m_vKeyState[dwKey] & 0x80) && (m_vKeyStateOld[dwKey] & 0x80); }
// 取按鍵狀態(tài) 若按下則返回true
bool GetKeyState(DWORD dwKey) { return (m_vKeyState[dwKey] & 0x80) != 0; }
// 取功能鍵狀態(tài)
ShiftState GetShiftState(void) { return m_ShiftState; }
// 自上次調(diào)用Update()后被按下的鍵
std::queue<DWORD> GetKeyDown(void) { return m_qKeyDownSave; }
// 自上次調(diào)用Update()后被松開的鍵
std::queue<DWORD> GetKeyUp(void) { return m_qKeyUpSave; }
// 自上次調(diào)用Update()后得到的字符
std::queue<char> GetChar(void) { return m_qCharSave; }
// 鼠標(biāo)按鈕函數(shù)
public:
// 指定鼠標(biāo)按鈕是否剛被按下
bool IsMouseJustDown(MouseButton mb);
// 指定鼠標(biāo)按鈕是否剛被松開
bool IsMouseJustUp(MouseButton mb);
// 取鼠標(biāo)按鈕狀態(tài) 若按下則返回true
bool GetMouseState(MouseButton mb);
// 取鼠標(biāo)滾輪滾動數(shù)
int GetMouseWheel(void) { return m_nWheelSave; }
// 鼠標(biāo)位置函數(shù)
public:
// 取鼠標(biāo)位置
POINT GetMousePos(void) { return m_ptMousePos; }
// 取鼠標(biāo)X坐標(biāo)
int GetMousePosX(void) { return m_ptMousePos.x; }
// 取鼠標(biāo)Y坐標(biāo)
int GetMousePosY(void) { return m_ptMousePos.y; }
// 設(shè)置鼠標(biāo)位置
void SetMousePos(POINT pt);
// 鼠標(biāo)是否移動(相對于上一次調(diào)用Update())
bool IsMouseMoved(void);
// 成員變量
private:
HWND m_hWnd; // 主窗口句柄
BYTE m_vKeyState[BUF_SIZE]; // 鍵盤緩沖
BYTE m_vKeyStateOld[BUF_SIZE]; // 前次鍵盤緩沖
ShiftState m_ShiftState; // 功能鍵狀態(tài)
POINT m_ptMousePos; // 鼠標(biāo)位置
POINT m_ptMousePosOld; // 前次鼠標(biāo)位置
std::queue<DWORD> m_qKeyDown; // 被按下鍵隊列
std::queue<DWORD> m_qKeyUp; // 被松開鍵隊列
std::queue<char> m_qChar; // 字符隊列
std::queue<DWORD> m_qKeyDownSave; // 保存的被按下鍵隊列
std::queue<DWORD> m_qKeyUpSave; // 保存的被松開鍵隊列
std::queue<char> m_qCharSave; // 保存的字符隊列
int m_nWheel; // 鼠標(biāo)滾輪滾動數(shù)
int m_nWheelSave; // 保存的鼠標(biāo)滾輪滾動數(shù)
}; // ASLInput類定義結(jié)束
} // namespace ASL
#endif // ASL_INPUT_INCLUDE
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -