diff --git a/src/addonloader/luaaddonstate.cpp b/src/addonloader/luaaddonstate.cpp index 525ad0f..49eb2e7 100644 --- a/src/addonloader/luaaddonstate.cpp +++ b/src/addonloader/luaaddonstate.cpp @@ -158,6 +158,7 @@ LuaAddonState::LuaAddonState(Library *luaLibrary, const std::string &name, {"removeQuickPhraseHandler", &LuaAddonState::removeQuickPhraseHandler}, {"commitString", &LuaAddonState::commitString}, + {"forwardKey", &LuaAddonState::forwardKey}, {"standardPathLocate", &LuaAddonState::standardPathLocate}, {"UTF16ToUTF8", &LuaAddonState::UTF16ToUTF8}, {"UTF8ToUTF16", &LuaAddonState::UTF8ToUTF16}, @@ -378,6 +379,15 @@ std::tuple<> LuaAddonState::commitStringImpl(const char *str) { return {}; } +std::tuple<> LuaAddonState::forwardKeyImpl(int keySym, int keyStates, bool release) { + if (auto *ic = inputContext_.get()) { + Key key(static_cast(keySym), static_cast(keyStates)); + ic->forwardKey(key, release); + } + return {}; +} + + bool LuaAddonState::handleQuickPhrase( InputContext *ic, const std::string &input, const QuickPhraseAddCandidateCallback &callback) { diff --git a/src/addonloader/luaaddonstate.h b/src/addonloader/luaaddonstate.h index 94139cc..53cf40c 100644 --- a/src/addonloader/luaaddonstate.h +++ b/src/addonloader/luaaddonstate.h @@ -175,6 +175,12 @@ class LuaAddonState { // @function commitString // @string str string to be commit to input context. DEFINE_LUA_FUNCTION(commitString); + /// Send a key event to client. + // @function forwardKey + // @int keySym A keySym of the key event. + // @int keyStates A modifier states of the key event. + // @boolean release Whether this is a key release event. + DEFINE_LUA_FUNCTION(forwardKey); /// Locate all files with given path and suffix. // @function standardPathLocate // @int type @@ -230,6 +236,8 @@ class LuaAddonState { standardPathLocateImpl(int type, const char *path, const char *suffix); std::tuple<> commitStringImpl(const char *str); + std::tuple<> forwardKeyImpl(int keySym, int keyStates, bool release); + FCITX_ADDON_DEPENDENCY_LOADER(quickphrase, instance_->addonManager()); bool handleQuickPhrase(InputContext *ic, const std::string &input,