GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
keyboard.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#include "keyboard.h"
9
10#include <Dxlib.h>
11
12
13namespace designlab
14{
15
17{
18 for (int i = 0; i < kKeyNum; i++)
19 {
20 key_releasing_counter_[i] = 0;
21 key_pressing_counter_[i] = 0;
22 }
23}
24
26{
27 char now_key_status[kKeyNum];
28 GetHitKeyStateAll(now_key_status); // 今のキーの入力状態を取得.
29
30 for (int i = 0; i < kKeyNum; i++)
31 {
32 if (now_key_status[i] != 0)
33 {
34 // i番のキーが押されていたら.
35
36 if (key_releasing_counter_[i] > 0)
37 {
38 // 離されカウンタが0より大きければ.
39 key_releasing_counter_[i] = 0; // 0に戻す.
40 }
41
42 key_pressing_counter_[i]++; // 押されカウンタを増やす.
43 }
44 else
45 {
46 // i番のキーが離されていたら.
47 if (key_pressing_counter_[i] > 0)
48 {
49 // 押されカウンタが0より大きければ.
50 key_pressing_counter_[i] = 0; // 0に戻す.
51 }
52
53 key_releasing_counter_[i]++; // 離されカウンタを増やす.
54 }
55 }
56}
57
58int Keyboard::GetPressingCount(const int key_code) const
59{
60 if (!IsAvailableCode(key_code))
61 {
62 return -1;
63 }
64
65 return key_pressing_counter_[key_code];
66}
67
68int Keyboard::GetReleasingCount(const int key_code) const
69{
70 if (!IsAvailableCode(key_code))
71 {
72 return -1;
73 }
74
75 return key_releasing_counter_[key_code];
76}
77
78bool Keyboard::IsAvailableCode(const int key_code) const
79{
80 if (!(0 <= key_code && key_code < kKeyNum))
81 {
82 return false;
83 }
84
85 return true;
86}
87
88} // namespace designlab
int GetReleasingCount(const int key_code) const
keyCodeのキーが離されているフレーム数を取得する.
Definition keyboard.cpp:68
void Update()
キー入力を更新する. これを毎フレーム実行しないと,キー入力を取得できない.
Definition keyboard.cpp:25
int GetPressingCount(const int key_code) const
keyCodeのキーが押されているフレーム数を取得する.
Definition keyboard.cpp:58