V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Neur2n
V2EX  ›  Linux

求助: ibus 和 fcitx 框架下的输入法状态切换

  •  
  •   Neur2n ·
    neur1n · 10 天前 · 570 次点击

    之前尝试使用 C++实现在 Vim 里面自动切换输入法(相关贴),后来有人提出是否可以只切换输入法状态而不是切换输入法——例如,模拟按Shift键切换中英文状态。

    近期发现 Win32 API 是可以实现 Windows 下输入法状态切换的(详情有兴趣可在评论区问),但是在 ibus 、fcitx 找不到类似的功能接口(在 ibux 的 Github 仓库提 issue 问过)。所以想请教各位佬,有什么“奇技淫巧”,可以通过一个外部程序,读写 ibus 、fcitx 输入法的状态。

    3 条回复    2024-06-11 14:52:34 +08:00
    billlee
        1
    billlee  
       10 天前
    这个状态应该要具体到某个特定输入法来控制,我用 fcitix + rime, dbus 里有 rime 的 setAsciiMode 接口
    ns09005264
        2
    ns09005264  
       9 天前
    fcitx5 可以通过 dbus 发送一些指令,比如我用的 fcitx5-rime 可以用这个指令切换中英状态,完整的 nvim lua 配置示例:
    ```
    vim.keymap.set({ "i", "n" }, "<esc>", function()
    io.popen(
    "dbus-send --session --print-reply --dest=org.fcitx.Fcitx5 /rime org.fcitx.Fcitx.Rime1.SetAsciiMode boolean:true"
    )
    return "<cmd>noh<cr><esc>"
    end, { expr = true, desc = "Exit insert mode to reset rime" })
    ```
    Neur2n
        3
    Neur2n  
    OP
       9 天前
    @billlee @ns09005264 感谢两位
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2960 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 12:26 · PVG 20:26 · LAX 05:26 · JFK 08:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.