DirectX/DirectX 2D_(구)

DX_Keyboard

컴맹학자 2020. 12. 21. 20:05
728x90

키보드 이벤트에 관한 내용을 class 만들어서 어디서든 키보드 이벤트에 관한 내용을 사용 할 수 있도록 만듬

 

Keyboard

더보기

Keyboard.cpp

#include "stdafx.h"
#include "Keyboard.h"
Keyboard::Keyboard(){
for (int i = 0; i < KEYMAX; i++) {
up.set(i, false);
down.set(i, false);
}
}
Keyboard::~Keyboard(){
}
//키보드를 입력 했을때
bool Keyboard::Down(int key)
{
if (GetAsyncKeyState(key) & 0x8000) {
if (down[key] == false) {
down.set(key, true);
return true;
}
}
else
{
down.set(key, false);
}
return false;
}
bool Keyboard::Up(int key)
{
if (GetAsyncKeyState(key) & 0x8000) {
up.set(key, true);
}
else {
if (up[key] == true) {
up.set(key, false);
return true;
}
}
return false;
}
bool Keyboard::Press(int key)
{
if (GetAsyncKeyState(key) & 0x8000) {
return true;
}
return false;
}
bool Keyboard::Toggle(int key)
{
if (GetAsyncKeyState(key) & 0x8001) {
return true;
}
return false;
}

keyboard.h

#pragma once
#define KEYMAX 256 //키보드 갯수
class Keyboard {
public:
Keyboard();
~Keyboard();
bool Down(int key); // 아스키 코드로 받음
bool Up(int key);
bool Press(int key);
bool Toggle(int key);
private:
bitset<KEYMAX> up; //bool up[256] <-- 같은 원리
bitset<KEYMAX> down; //bool down[256] <-- 같은 원리
};

 


해당 키보드 class 이용해서 미리 적용한 오브젝트 이동을 실행한 내용

 

 

'DirectX > DirectX 2D_(구)' 카테고리의 다른 글

DX_카메라 시점변환  (0) 2021.01.05
DX_Move  (0) 2020.12.23
DX_DirectWrite  (0) 2020.11.24
DX_카메라 (고정, 자유)  (0) 2020.11.18
DX_ Clip, Animation  (0) 2020.11.17