# Khaotic Engine Reborn: input_class Class Reference

Loading...
Searching...
No Matches
input_class Class Reference

## Public Member Functions

| input_class (const input_class &)
virtual bool | Initialize (HINSTANCE, HWND, int, int)
virtual void | Shutdown ()
virtual bool | Frame ()
bool | IsEscapePressed () const
void | GetMouseLocation (int &, int &) const
bool | IsLeftMousePressed () const
bool | IsRightMousePressed () const
void | KeyDown (unsigned int)
void | KeyUp (unsigned int)
bool | IsLeftArrowPressed () const
bool | IsRightArrowPressed () const
bool | IsScrollUp () const
bool | IsScrollDown () const
bool | IsUpArrowPressed () const
bool | IsDownArrowPressed () const
bool | IsAPressed () const
bool | IsDPressed () const
bool | IsWPressed () const
bool | IsSPressed () const
bool | IsQPressed () const
bool | IsEPressed () const
bool | IsKeyDown (unsigned int) const
bool | is_key_pressed (const unsigned int)

## Detailed Description

Definition at line 24 of file input_class.h.

## Constructor & Destructor Documentation

## input_class() [1/2]

input_class::input_class | ( |  | ) |

Definition at line 4 of file input_class.cpp.

{
m_directInput = 0;
m_keyboard = 0;
m_mouse = 0;
m_previousTildeState = false;
}

## input_class() [2/2]

input_class::input_class | ( | const input_class & | other | ) |

Definition at line 13 of file input_class.cpp.

{
}

## ~input_class()

input_class::~input_class | ( |  | ) |

Definition at line 18 of file input_class.cpp.

{
}

## Member Function Documentation

## Frame()

bool input_class::Frame | ( |  | ) |

virtual

Definition at line 176 of file input_class.cpp.

{
bool result;
// Read the current state of the keyboard.
result = ReadKeyboard();
if (!result)
{
Logger::Get().Log("Failed to read keyboard state", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Read the current state of the mouse.
result = ReadMouse();
if (!result)
{
Logger::Get().Log("Failed to read mouse state", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Process the changes in the mouse and keyboard.
ProcessInput();
return true;
}

## GetMouseLocation()

void input_class::GetMouseLocation | ( | int & | mouseX,
|  | int & | mouseY ) const

Definition at line 387 of file input_class.cpp.

{
mouseX = m_mouseX;
mouseY = m_mouseY;
return;
}

## Initialize()

bool input_class::Initialize | ( | HINSTANCE | hinstance,
|  | HWND | hwnd,
|  | int | screenWidth,
|  | int | screenHeight )

virtual

Definition at line 22 of file input_class.cpp.

{
Logger::Get().Log("Initializing input class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
HRESULT result;
int i;
// Initialize all the keys to being released and not pressed.
for (i = 0; i < 256; i++)
{
m_keys[i] = false;
}
// Store the screen size which will be used for positioning the mouse cursor.
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
// Initialize the location of the mouse on the screen.
m_mouseX = 0;
m_mouseY = 0;
// Initialize the main direct input interface.
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
if (FAILED(result))
{
Logger::Get().Log("Failed to create direct input interface", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Initialize the direct input interface for the keyboard.
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
if (FAILED(result))
{
Logger::Get().Log("Failed to create direct input interface for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the data format. In this case since it is a keyboard we can use the predefined data format.
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
if (FAILED(result))
{
Logger::Get().Log("Failed to set data format for the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the cooperative level of the keyboard to share with other programs.
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(result))
{
Logger::Get().Log("Failed to set cooperative level of the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Now acquire the keyboard.
result = m_keyboard->Acquire();
if (FAILED(result))
{
Logger::Get().Log("Failed to acquire the keyboard", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Initialize the direct input interface for the mouse.
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
if (FAILED(result))
{
Logger::Get().Log("Failed to create direct input interface for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the data format for the mouse using the pre-defined mouse data format.
result = m_mouse->SetDataFormat(&c_dfDIMouse);
if (FAILED(result))
{
Logger::Get().Log("Failed to set data format for the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the cooperative level of the mouse to share with other programs.
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(result))
{
Logger::Get().Log("Failed to set cooperative level of the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Acquire the mouse.
result = m_mouse->Acquire();
if (FAILED(result))
{
Logger::Get().Log("Failed to acquire the mouse", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
Logger::Get().Log("Input class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}

## is_key_pressed()

bool input_class::is_key_pressed | ( | const unsigned int | key_code | ) |

Definition at line 436 of file input_class.cpp.

{
if (m_keyboardState[key_code] & 0x80)
{
return true;
}
return false;
}

## IsAPressed()

bool input_class::IsAPressed | ( |  | ) | const

Definition at line 324 of file input_class.cpp.

{
// Touche A sur QWERTY, Q sur AZERTY
if (m_keyboardState[DIK_A] & 0x80)
{
return true;
}
return false;
}

## IsDownArrowPressed()

bool input_class::IsDownArrowPressed | ( |  | ) | const

Definition at line 310 of file input_class.cpp.

{
if (m_keyboardState[DIK_DOWN] & 0x80)
{
return true;
}
return false;
}

## IsDPressed()

bool input_class::IsDPressed | ( |  | ) | const

Definition at line 335 of file input_class.cpp.

{
if (m_keyboardState[DIK_D] & 0x80)
{
return true;
}
return false;
}

## IsEPressed()

bool input_class::IsEPressed | ( |  | ) | const

Definition at line 377 of file input_class.cpp.

{
if (m_keyboardState[DIK_E] & 0x80)
{
return true;
}
return false;
}

## IsEscapePressed()

bool input_class::IsEscapePressed | ( |  | ) | const

Definition at line 267 of file input_class.cpp.

{
// Do a bitwise and on the keyboard state to check if the escape key is currently being pressed.
if (m_keyboardState[DIK_ESCAPE] & 0x80)
{
return true;
}
return false;
}

## IsKeyDown()

bool input_class::IsKeyDown | ( | unsigned int | key | ) | const

Definition at line 138 of file input_class.cpp.

{
// Return what state the key is in (pressed/not pressed).
return m_keys[key];
}

## IsLeftArrowPressed()

bool input_class::IsLeftArrowPressed | ( |  | ) | const

Definition at line 278 of file input_class.cpp.

{
if (m_keyboardState[DIK_LEFT] & 0x80)
{
return true;
}
return false;
}

## IsLeftMousePressed()

bool input_class::IsLeftMousePressed | ( |  | ) | const

Definition at line 394 of file input_class.cpp.

{
// Check the left mouse button state.
if (m_mouseState.rgbButtons[0] & 0x80)
{
return true;
}
return false;
}

## IsQPressed()

bool input_class::IsQPressed | ( |  | ) | const

Definition at line 366 of file input_class.cpp.

{
// Touche Q sur QWERTY, A sur AZERTY
if (m_keyboardState[DIK_Q] & 0x80)
{
return true;
}
return false;
}

## IsRightArrowPressed()

bool input_class::IsRightArrowPressed | ( |  | ) | const

Definition at line 289 of file input_class.cpp.

{
if (m_keyboardState[DIK_RIGHT] & 0x80)
{
return true;
}
return false;
}

## IsRightMousePressed()

bool input_class::IsRightMousePressed | ( |  | ) | const

Definition at line 405 of file input_class.cpp.

{
// Check the left mouse button state.
if (m_mouseState.rgbButtons[1] & 0x80)
{
return true;
}
return false;
}

## IsScrollDown()

bool input_class::IsScrollDown | ( |  | ) | const

Definition at line 426 of file input_class.cpp.

{
if (m_mouseState.lZ < 0)
{
return true;
}
return false;
}

## IsScrollUp()

bool input_class::IsScrollUp | ( |  | ) | const

Definition at line 416 of file input_class.cpp.

{
if (m_mouseState.lZ > 0)
{
return true;
}
return false;
}

## IsSPressed()

bool input_class::IsSPressed | ( |  | ) | const

Definition at line 356 of file input_class.cpp.

{
if (m_keyboardState[DIK_S] & 0x80)
{
return true;
}
return false;
}

## IsUpArrowPressed()

bool input_class::IsUpArrowPressed | ( |  | ) | const

Definition at line 299 of file input_class.cpp.

{
if (m_keyboardState[DIK_UP] & 0x80)
{
return true;
}
return false;
}

## IsWPressed()

bool input_class::IsWPressed | ( |  | ) | const

Definition at line 345 of file input_class.cpp.

{
// Touche W sur QWERTY, Z sur AZERTY
if (m_keyboardState[DIK_W] & 0x80)
{
return true;
}
return false;
}

## KeyDown()

void input_class::KeyDown | ( | unsigned int | input | ) |

Definition at line 121 of file input_class.cpp.

{
// If a key is pressed then save that state in the key array.
Logger::Get().Log("Key down: " + std::to_string(input), __FILE__, __LINE__, Logger::LogLevel::Input);
m_keys[input] = true;
return;
}
input
Definition application_class.h:68

## KeyUp()

void input_class::KeyUp | ( | unsigned int | input | ) |

Definition at line 130 of file input_class.cpp.

{
// If a key is released then clear that state in the key array.
m_keys[input] = false;
return;
}

## Shutdown()

void input_class::Shutdown | ( |  | ) |

virtual

Definition at line 144 of file input_class.cpp.

{
Logger::Get().Log("Shutting down input class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
// Release the mouse.
if (m_mouse)
{
m_mouse->Unacquire();
m_mouse->Release();
m_mouse = 0;
}
// Release the keyboard.
if (m_keyboard)
{
m_keyboard->Unacquire();
m_keyboard->Release();
m_keyboard = 0;
}
// Release the main interface to direct input.
if (m_directInput)
{
m_directInput->Release();
m_directInput = 0;
}
Logger::Get().Log("Input class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
return;
}

The documentation for this class was generated from the following files:

- enginecustom/src/inc/system/input_class.h
- enginecustom/src/src/system/input_class.cpp