Program Listing for File keycontrol.cpp¶
↰ Return to documentation for file (blam\components\input\keycontrol.cpp
)
// Blamite Engine - Debug/DevTools UI //
// (c) Elaztek Studios 2016-2019 //
/*
to get RAW KEY INPUT (not filtered/held/paused/wtv its called for typing) for movement/game controls, use:
GetAsyncKeyState();
this file used to be fucking abysmal, check gitlab history if you want your eyes to bleed
*/
#include "keyboard.h"
#include "components/rendering/directx11/render_stack/render_stack.h"
#include "components/rendering/directx11/render_stack/stack_types/blam_ui/console.hpp"
#include "components/rendering/directx11/render_stack/stack_types/blam_ui/debug_menu.hpp"
#include <vector>
//#include <WinUser.h>
using namespace BlamRendering::RenderStack;
std::vector<int> special_keys =
{
// these are handled by WM_KEYDOWN
VK_BACK, VK_LEFT, VK_RIGHT, VK_RETURN, VK_UP, VK_DOWN, VK_TAB, VK_F1, VK_F2, VK_F3, VK_F4,
VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_F10, VK_F11, VK_F12, VK_HOME
};
bool isSpecialKey(WPARAM virtual_key)
{
bool is_special = false;
for (int i = 0; i < special_keys.size(); i++)
{
if (special_keys.at(i) == virtual_key)
{
is_special = true;
break;
}
}
return is_special;
}
std::vector<char> normal_chars =
{
'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J',
'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's',
'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '0', '!', '@', '#', '$', '%', '^', '&', '(', ')', '[', ']', ';', ':', '"',
'\'', '<', '>', ',', '.', '/', '?', '\\', '|', '`', '~', ' ', '-', '=', '_', '+'
};
bool isRegularKey(WPARAM virtual_key)
{
char character = (char)virtual_key;
bool is_normal = false;
for (int i = 0; i < normal_chars.size(); i++)
{
if (normal_chars.at(i) == character)
{
is_normal = true;
break;
}
}
return is_normal;
}
// Handle character-based input (WM_CHAR message)
int Blam::Input::HandleCharacterInput(WPARAM wParam)
{
if (isRegularKey(wParam))
{
//character pressed
char character = (char)wParam;
Blam::Events::CharacterInputEvent event(character);
Blam::Events::FireEvent(&event);
return 0;
}
}
// Handle key press events (WM_KEYDOWN message)
int Blam::Input::HandleKeyPress(WPARAM wParam)
{
Blam::Events::KeyPressEvent event(wParam);
Blam::Events::FireEvent(&event);
switch (wParam)
{
case VK_F2:
{
Blam::TakeScreenshot();
break;
}
default:
{
break;
}
}
return 0;
}