0% found this document useful (0 votes)
175 views2 pages

Hazel Game Engine

This document defines several classes related to keyboard input events in a game engine: KeyEvent is the base class for keyboard events, KeyPressedEvent contains information about a key press including the repeat count, KeyReleasedEvent contains information about a key release, and KeyTypedEvent contains information about a typed key press. These classes store the key code and provide functions to get key code and string representations of the events.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views2 pages

Hazel Game Engine

This document defines several classes related to keyboard input events in a game engine: KeyEvent is the base class for keyboard events, KeyPressedEvent contains information about a key press including the repeat count, KeyReleasedEvent contains information about a key release, and KeyTypedEvent contains information about a typed key press. These classes store the key code and provide functions to get key code and string representations of the events.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#pragma once

#include "Hazel/Events/Event.h"
#include "Hazel/Core/KeyCodes.h"

namespace Hazel {

class KeyEvent : public Event


{
public:
KeyCode GetKeyCode() const { return m_KeyCode; }

EVENT_CLASS_CATEGORY(EventCategoryKeyboard | EventCategoryInput)
protected:
KeyEvent(const KeyCode keycode)
: m_KeyCode(keycode) {}

KeyCode m_KeyCode;
};

class KeyPressedEvent : public KeyEvent


{
public:
KeyPressedEvent(const KeyCode keycode, const uint16_t repeatCount)
: KeyEvent(keycode), m_RepeatCount(repeatCount) {}

uint16_t GetRepeatCount() const { return m_RepeatCount; }

std::string ToString() const override


{
std::stringstream ss;
ss << "KeyPressedEvent: " << m_KeyCode << " (" << m_RepeatCount
<< " repeats)";
return ss.str();
}

EVENT_CLASS_TYPE(KeyPressed)
private:
uint16_t m_RepeatCount;
};

class KeyReleasedEvent : public KeyEvent


{
public:
KeyReleasedEvent(const KeyCode keycode)
: KeyEvent(keycode) {}

std::string ToString() const override


{
std::stringstream ss;
ss << "KeyReleasedEvent: " << m_KeyCode;
return ss.str();
}

EVENT_CLASS_TYPE(KeyReleased)
};

class KeyTypedEvent : public KeyEvent


{
public:
KeyTypedEvent(const KeyCode keycode)
: KeyEvent(keycode) {}

std::string ToString() const override


{
std::stringstream ss;
ss << "KeyTypedEvent: " << m_KeyCode;
return ss.str();
}

EVENT_CLASS_TYPE(KeyTyped)
};
}

You might also like