Fix alt buttons and add hack to combat flickery key presses (far from perfect)
This commit is contained in:
parent
1f0115800c
commit
3ee97ceb4f
|
|
@ -58,7 +58,7 @@ void App::Update()
|
|||
DisableCursor();
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_LEFT_ALT)) //Unable to get working on my PC
|
||||
if (IsKeyDown(KEY_LEFT_ALT))
|
||||
DrawRectangle(250, 250, 20, 20, BLACK);
|
||||
if (IsKeyDown(KEY_BACKSPACE))
|
||||
DrawRectangle(280, 250, 20, 20, BLACK);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,12 @@
|
|||
|
||||
#include "pch.h"
|
||||
|
||||
//Define what header we use for BaseApp.h
|
||||
#define PCH "pch.h"
|
||||
|
||||
//Enable hold hack
|
||||
#define HOLDHACK
|
||||
|
||||
#include "BaseApp.h"
|
||||
|
||||
namespace raylibUWP
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@
|
|||
*
|
||||
* #define PCH
|
||||
* This defines what header is the PCH and needs to be included
|
||||
*
|
||||
* #define HOLDHACK
|
||||
* This enables a hack to fix flickering key presses (Temporary)
|
||||
*
|
||||
* Copyright (c) 2013-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
|
|
@ -200,6 +203,59 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
// Process Keyboard
|
||||
{
|
||||
for (int k = 0x08; k < 0xA6; k++) {
|
||||
auto state = CoreWindow::GetForCurrentThread()->GetKeyState((Windows::System::VirtualKey) k);
|
||||
|
||||
#ifdef HOLDHACK
|
||||
//Super hacky way of waiting three frames to see if we are ready to register the key as deregistered
|
||||
//This will wait an entire 4 frames before deregistering the key, this makes sure that the key is not flickering
|
||||
if (KeyboardStateHack[k] == 2)
|
||||
{
|
||||
if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None)
|
||||
{
|
||||
KeyboardStateHack[k] = 3;
|
||||
}
|
||||
}
|
||||
else if (KeyboardStateHack[k] == 3)
|
||||
{
|
||||
if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None)
|
||||
{
|
||||
KeyboardStateHack[k] = 4;
|
||||
}
|
||||
}
|
||||
else if (KeyboardStateHack[k] == 4)
|
||||
{
|
||||
if ((state & CoreVirtualKeyStates::None) == CoreVirtualKeyStates::None)
|
||||
{
|
||||
//Reset key...
|
||||
KeyboardStateHack[k] = 0;
|
||||
|
||||
//Tell core
|
||||
RegisterKey(k, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//Left and right alt, KeyUp and KeyDown are not called for it
|
||||
//No need to hack because this is not a character
|
||||
|
||||
//TODO: Maybe do all other key registrations like this, no more key events?
|
||||
|
||||
if (k == 0xA4 || k == 0xA5)
|
||||
{
|
||||
if ((state & CoreVirtualKeyStates::Down) == CoreVirtualKeyStates::Down)
|
||||
{
|
||||
RegisterKey(k, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
RegisterKey(k, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process Mouse
|
||||
{
|
||||
|
||||
|
|
@ -372,25 +428,52 @@ protected:
|
|||
|
||||
void OnKeyDown(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args)
|
||||
{
|
||||
UWPMessage* msg = CreateUWPMessage();
|
||||
msg->Type = RegisterKey;
|
||||
msg->Int0 = (int)args->VirtualKey;
|
||||
msg->Char0 = 1;
|
||||
UWPSendMessage(msg);
|
||||
#ifdef HOLDHACK
|
||||
//Start the hack
|
||||
KeyboardStateHack[(int)args->VirtualKey] = 1;
|
||||
#endif
|
||||
|
||||
RegisterKey((int)args->VirtualKey, 1);
|
||||
}
|
||||
|
||||
void OnKeyUp(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::KeyEventArgs ^ args)
|
||||
{
|
||||
//TODO: Fix hold errors
|
||||
UWPMessage* msg = CreateUWPMessage();
|
||||
msg->Type = RegisterKey;
|
||||
msg->Int0 = (int)args->VirtualKey;
|
||||
msg->Char0 = 0;
|
||||
UWPSendMessage(msg);
|
||||
#ifdef HOLDHACK
|
||||
//The same hack
|
||||
if (KeyboardStateHack[(int)args->VirtualKey] == 1)
|
||||
{
|
||||
KeyboardStateHack[(int)args->VirtualKey] = 2;
|
||||
}
|
||||
else if (KeyboardStateHack[(int)args->VirtualKey] == 2)
|
||||
{
|
||||
KeyboardStateHack[(int)args->VirtualKey] = 3;
|
||||
}
|
||||
else if (KeyboardStateHack[(int)args->VirtualKey] == 3)
|
||||
{
|
||||
KeyboardStateHack[(int)args->VirtualKey] = 4;
|
||||
}
|
||||
else if (KeyboardStateHack[(int)args->VirtualKey] == 4)
|
||||
{
|
||||
RegisterKey((int)args->VirtualKey, 0);
|
||||
KeyboardStateHack[(int)args->VirtualKey] = 0;
|
||||
}
|
||||
#else
|
||||
//No hack, allow flickers
|
||||
RegisterKey((int)args->VirtualKey, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void RegisterKey(int key, char status)
|
||||
{
|
||||
UWPMessage* msg = CreateUWPMessage();
|
||||
msg->Type = UWPMessageType::RegisterKey;
|
||||
msg->Int0 = key;
|
||||
msg->Char0 = status;
|
||||
UWPSendMessage(msg);
|
||||
}
|
||||
|
||||
void MoveMouse(Vector2 pos)
|
||||
{
|
||||
CoreWindow ^window = CoreWindow::GetForCurrentThread();
|
||||
|
|
@ -442,6 +525,10 @@ private:
|
|||
int height = 480;
|
||||
|
||||
int CurrentPointerID = -1;
|
||||
|
||||
#ifdef HOLDHACK
|
||||
char KeyboardStateHack[0xA6]; //0xA6 because the highest key we compare against is 0xA5
|
||||
#endif
|
||||
};
|
||||
|
||||
//Application source for creating the program
|
||||
|
|
|
|||
|
|
@ -3220,6 +3220,9 @@ static void PollInputEvents(void)
|
|||
|
||||
if (actualKey > -1)
|
||||
currentKeyState[actualKey] = msg->Char0;
|
||||
|
||||
if (msg->Char0)
|
||||
msg->Char0 = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ static int android_close(void *cookie)
|
|||
|
||||
#if defined(PLATFORM_UWP)
|
||||
|
||||
#define MAX_MESSAGES 128 //If there are over 128 messages, I will cry... either way, this may be too much
|
||||
#define MAX_MESSAGES 512 //If there are over 128 messages, I will cry... either way, this may be too much EDIT: Welp, 512
|
||||
|
||||
static int UWPOutMessageId = -1; //Stores the last index for the message
|
||||
static UWPMessage* UWPOutMessages[MAX_MESSAGES]; //Messages out to UWP
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user