diff --git a/README.md b/README.md index c262c7c..885f4db 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The project is using make. You can edit ./conf/settings.txt after copy if needed make clean make release mkdir ./conf -cp ./settings.txt /conf +cp ./settings.txt ./conf ./out/app ./conf/settings.txt ``` diff --git a/settings.txt b/settings.txt index 7f77a93..fc46cd7 100644 --- a/settings.txt +++ b/settings.txt @@ -134,6 +134,14 @@ #on-connect-script = #on-disconnect-script = +# Map extra keys for control with there codes +# If you set logging true you and press keys you will see there codes in logs +#key-left = 0 +#key-right = 0 +#key-enter = 0 +#key-back = 0 +#key-home = 0 + ############################################################################## # 4.Debug ############################################################################## diff --git a/src/helper/protocol_const.h b/src/helper/protocol_const.h index 998bbe0..c788e56 100644 --- a/src/helper/protocol_const.h +++ b/src/helper/protocol_const.h @@ -35,6 +35,14 @@ #define CMD_VERSION 204 #define CMD_ENCRYPTION 240 +#define BTN_LEFT 100 +#define BTN_RIGHT 101 +#define BTN_SELECT_DOWN 104 +#define BTN_SELECT_UP 105 +#define BTN_BACK 106 +#define BTN_HOME 200 + + #define AUDIO_BUFFER_SIZE 2560 #define AUDIO_BUFFER_OFFSET 12 diff --git a/src/main.cpp b/src/main.cpp index df98f84..414310a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,32 +51,60 @@ void processKey(Protocol &protocol, SDL_Keysym key, RunParams ¶ms) params.fullscreen = !params.fullscreen; // Toggle fullscreen mode SDL_SetWindowFullscreen(window, params.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); SDL_SetWindowBordered(window, params.fullscreen ? SDL_FALSE : SDL_TRUE); - break; + return; case SDLK_q: active = false; - break; + return; case SDLK_r: params.dirty = true; - break; + return; case SDLK_LEFT: - protocol.sendKey(100); - break; + protocol.sendKey(BTN_LEFT); + return; case SDLK_RIGHT: - protocol.sendKey(101); - break; + protocol.sendKey(BTN_RIGHT); + return; case SDLK_RETURN: - protocol.sendKey(104); - protocol.sendKey(105); - break; + protocol.sendKey(BTN_SELECT_DOWN); + protocol.sendKey(BTN_SELECT_UP); + return; case SDLK_BACKSPACE: - protocol.sendKey(106); - break; + protocol.sendKey(BTN_BACK); + return; + + case 0: + return; + } + + if (key.sym == Settings::keyLeft) + { + protocol.sendKey(BTN_LEFT); + } + else if (key.sym == Settings::keyRight) + { + protocol.sendKey(BTN_RIGHT); + } + else if (key.sym == Settings::keyEnter) + { + protocol.sendKey(BTN_SELECT_DOWN); + protocol.sendKey(BTN_SELECT_UP); + } + else if (key.sym == Settings::keyBack) + { + protocol.sendKey(BTN_BACK); + } + else if (key.sym == Settings::keyHome) + { + protocol.sendKey(BTN_HOME); + } else + { + std::cout << "[Key] Unmapped key " << key.sym << std::endl; } } diff --git a/src/settings.h b/src/settings.h index ca75e8a..6ff27ac 100644 --- a/src/settings.h +++ b/src/settings.h @@ -26,13 +26,11 @@ public: static inline Setting wifi5{"wifi-5", true}; static inline Setting bluetoothAudio{"bluetooth-audio", false}; static inline Setting micType{"mic-type", 1}; - static inline Setting dpi{"android-dpi", 120}; + static inline Setting dpi{"android-dpi", 120}; static inline Setting androidMode{"android-resolution", 0}; - static inline Setting mediaDelay{"android-media-delay", 300}; + static inline Setting mediaDelay{"android-media-delay", 300}; - - - // Application configuration section + // Application configuration section static inline Setting fontSize{"font-size", 30}; static inline Setting vsync{"vsync", false}; static inline Setting aspectCorrection{"aspect-correction", 1}; @@ -40,11 +38,16 @@ public: static inline Setting videoQueue{"video-buffer-size", 32}; static inline Setting audioQueue{"audio-buffer-size", 16}; static inline Setting audioDelay{"audio-buffer-wait", 2}; - static inline Setting audioDelayCall{"audio-buffer-wait-call", 8}; + static inline Setting audioDelayCall{"audio-buffer-wait-call", 8}; static inline Setting audioFade{"audio-fade", 0.3}; static inline Setting audioDriver{"audio-driver", ""}; static inline Setting onConnect{"on-connect-script", ""}; static inline Setting onDisconnect{"on-disconnect-script", ""}; + static inline Setting keyLeft{"key-left", 0}; + static inline Setting keyRight{"key-right", 0}; + static inline Setting keyEnter{"key-enter", 0}; + static inline Setting keyBack{"key-back", 0}; + static inline Setting keyHome{"key-home", 0}; // Debug section static inline Setting protocolDebug{"protocol-debug", 0};