mirror of
https://github.com/moonlight-stream/moonlight-chrome.git
synced 2025-08-17 16:46:31 +00:00
Implement keyboard input support
This commit is contained in:
parent
8713d261aa
commit
2cd4856786
67
input.cpp
67
input.cpp
@ -6,6 +6,12 @@
|
|||||||
|
|
||||||
#include <Limelight.h>
|
#include <Limelight.h>
|
||||||
|
|
||||||
|
#define KEY_PREFIX 0x80
|
||||||
|
|
||||||
|
#define KEY_CODE_ALT 18
|
||||||
|
#define KEY_CODE_CTRL 17
|
||||||
|
#define KEY_CODE_SHIFT 16
|
||||||
|
|
||||||
static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) {
|
static int ConvertPPButtonToLiButton(PP_InputEvent_MouseButton ppButton) {
|
||||||
switch (ppButton) {
|
switch (ppButton) {
|
||||||
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
|
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
|
||||||
@ -27,6 +33,37 @@ void MoonlightInstance::MouseLockLost() {
|
|||||||
m_MouseLocked = false;
|
m_MouseLocked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MoonlightInstance::UpdateModifiers(PP_InputEvent_Type eventType, short keyCode) {
|
||||||
|
switch (keyCode) {
|
||||||
|
case KEY_CODE_ALT:
|
||||||
|
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
|
||||||
|
m_KeyModifiers |= MODIFIER_ALT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_KeyModifiers &= ~MODIFIER_ALT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_CODE_CTRL:
|
||||||
|
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
|
||||||
|
m_KeyModifiers |= MODIFIER_CTRL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_KeyModifiers &= ~MODIFIER_CTRL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_CODE_SHIFT:
|
||||||
|
if (eventType == PP_INPUTEVENT_TYPE_KEYDOWN) {
|
||||||
|
m_KeyModifiers |= MODIFIER_SHIFT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_KeyModifiers &= ~MODIFIER_SHIFT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
||||||
switch (event.GetType()) {
|
switch (event.GetType()) {
|
||||||
case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
|
case PP_INPUTEVENT_TYPE_MOUSEDOWN: {
|
||||||
@ -80,6 +117,36 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case PP_INPUTEVENT_TYPE_KEYDOWN: {
|
||||||
|
if (!m_MouseLocked) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pp::KeyboardInputEvent keyboardEvent(event);
|
||||||
|
|
||||||
|
// Update modifier state before sending the key event
|
||||||
|
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
|
||||||
|
|
||||||
|
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
||||||
|
KEY_ACTION_DOWN, m_KeyModifiers);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
case PP_INPUTEVENT_TYPE_KEYUP: {
|
||||||
|
if (!m_MouseLocked) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pp::KeyboardInputEvent keyboardEvent(event);
|
||||||
|
|
||||||
|
// Update modifier state before sending the key event
|
||||||
|
UpdateModifiers(event.GetType(), keyboardEvent.GetKeyCode());
|
||||||
|
|
||||||
|
LiSendKeyboardEvent(KEY_PREFIX << 8 | keyboardEvent.GetKeyCode(),
|
||||||
|
KEY_ACTION_UP, m_KeyModifiers);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "ppapi/cpp/video_decoder.h"
|
#include "ppapi/cpp/video_decoder.h"
|
||||||
|
|
||||||
#include "ppapi/c/ppb_gamepad.h"
|
#include "ppapi/c/ppb_gamepad.h"
|
||||||
|
#include "ppapi/c/pp_input_event.h"
|
||||||
#include "ppapi/c/ppb_opengles2.h"
|
#include "ppapi/c/ppb_opengles2.h"
|
||||||
#include "ppapi/cpp/graphics_3d.h"
|
#include "ppapi/cpp/graphics_3d.h"
|
||||||
#include "ppapi/cpp/graphics_3d_client.h"
|
#include "ppapi/cpp/graphics_3d_client.h"
|
||||||
@ -36,7 +37,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
|||||||
pp::MouseLock(this),
|
pp::MouseLock(this),
|
||||||
m_IsPainting(false),
|
m_IsPainting(false),
|
||||||
m_CallbackFactory(this),
|
m_CallbackFactory(this),
|
||||||
m_MouseLocked(false) {
|
m_MouseLocked(false),
|
||||||
|
m_KeyModifiers(0) {
|
||||||
// This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!)
|
// This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!)
|
||||||
nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface());
|
nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface());
|
||||||
|
|
||||||
@ -49,6 +51,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
|||||||
|
|
||||||
void HandleMessage(const pp::Var& var_message);
|
void HandleMessage(const pp::Var& var_message);
|
||||||
|
|
||||||
|
void UpdateModifiers(PP_InputEvent_Type eventType, short keyCode);
|
||||||
bool HandleInputEvent(const pp::InputEvent& event);
|
bool HandleInputEvent(const pp::InputEvent& event);
|
||||||
|
|
||||||
void PollGamepads();
|
void PollGamepads();
|
||||||
@ -100,6 +103,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
|
|||||||
const PPB_Gamepad* m_GamepadApi;
|
const PPB_Gamepad* m_GamepadApi;
|
||||||
pp::CompletionCallbackFactory<MoonlightInstance> m_CallbackFactory;
|
pp::CompletionCallbackFactory<MoonlightInstance> m_CallbackFactory;
|
||||||
bool m_MouseLocked;
|
bool m_MouseLocked;
|
||||||
|
char m_KeyModifiers;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MoonlightInstance* g_Instance;
|
extern MoonlightInstance* g_Instance;
|
Loading…
x
Reference in New Issue
Block a user