KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
KeyEvent.h
Go to the documentation of this file.
1
10#pragma once
11
12#include "krpch.h"
13
14#include "Event.h"
15
16namespace Karma
17{
21 class KARMA_API KeyEvent : public Event
22 {
23 public:
29 inline int GetKeyCode() const { return m_KeyCode; }
30
32
33 protected:
42 KeyEvent(int keycode) : m_KeyCode(keycode)
43 {
44 }
45
46 int m_KeyCode;
47 };
48
53 {
54 public:
64 KeyPressedEvent(int keycode, int repeatCount)
65 : KeyEvent(keycode), m_RepeatCount(repeatCount)
66 {
67 }
68
74 inline int GetRepeatCount() const { return m_RepeatCount; }
75
81 std::string ToString() const override
82 {
83 std::stringstream ss;
84 ss << "KeyPressedEvent: " << m_KeyCode << " ( " << m_RepeatCount << " repeats)";
85 return ss.str();
86 }
87
88 EVENT_CLASS_TYPE(KeyPressed)
89 private:
90 int m_RepeatCount;
91 };
92
97 {
98 public:
107 KeyReleasedEvent(int keycode) : KeyEvent(keycode)
108 {
109 }
110
116 std::string ToString() const override
117 {
118 std::stringstream ss;
119 ss << "KeyReleasedEvent: " << m_KeyCode;
120 return ss.str();
121 }
122
123 EVENT_CLASS_TYPE(KeyReleased)
124 };
125
130 {
131 public:
140 KeyTypedEvent(int keycode)
141 : KeyEvent(keycode)
142 {
143 }
144
150 std::string ToString() const override
151 {
152 std::stringstream ss;
153 ss << "KeyTypedEvent: " << m_KeyCode;
154 return ss.str();
155 }
156
157 EVENT_CLASS_TYPE(KeyTyped)
158 };
159}
#define KARMA_API
Defining Karma's API macro for storage class information.
Definition Core.h:41
This file contains the base class Event for Karma's events.
@ EventCategoryInput
Events belonging to game inputs. Input device examples include keyboard, mouse, and all that.
Definition Event.h:47
@ EventCategoryKeyboard
Events belonging to game inputs from keyboard (keyboard buttons pressing for instance)
Definition Event.h:52
#define EVENT_CLASS_TYPE(type)
A macro for a template for Event based classes.
Definition Event.h:75
#define EVENT_CLASS_CATEGORY(category)
Macro for the routine category flags.
Definition Event.h:84
The base class of all the events for Karma.
Definition Event.h:90
KeyEvent(int keycode)
A constructor.
Definition KeyEvent.h:42
int GetKeyCode() const
Getter for key code of the keyboard event.
Definition KeyEvent.h:29
std::string ToString() const override
String representation of the event.
Definition KeyEvent.h:81
KeyPressedEvent(int keycode, int repeatCount)
A constructor.
Definition KeyEvent.h:64
int GetRepeatCount() const
Getter for key repeat counter.
Definition KeyEvent.h:74
std::string ToString() const override
String representation of th event.
Definition KeyEvent.h:116
KeyReleasedEvent(int keycode)
A constructor.
Definition KeyEvent.h:107
KeyTypedEvent(int keycode)
A constructor.
Definition KeyEvent.h:140
std::string ToString() const override
String representation of the event.
Definition KeyEvent.h:150