7

Linux 下在 Minecraft 里输入中文

 2 years ago
source link: https://blog.lilydjwg.me/2015/5/17/input-chinese-to-minecraft-in-linux.93167.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux 下在 Minecraft 里输入中文

本文来自依云's Blog,转载请注明。

Linux 下各种奇怪的地方总是会遇到输入启用不了的情况,比如 Sublime Text 就需要打补丁版。Teewords 以前能好好地使用输入法的,不知从什么时候起,启用输入法输入时,直接从键盘输入的编码和输入法提交的字符串都会被 teewords 接收并显示(teewords 版本号 0.6.3)。最近换了新本子,跑起 Minecraft 终于不那么卡了,所以也研究了一下怎么在 mc 里输入中文。

喵窝 wiki 里给出了一个脚本,是通过外部程序输入中文,然后粘贴到 mc 里来达到输入中文的效果的。然而粘贴功能在我的 mc 里是无效的。不过照着这思路,改进一下发现也能用。

首先,需要 xdotools。其次,需要一个输入文本的程序。我使用的是 zentiy,当然还有 kdialog、gdialog 之类的也可以用。最后,需要设置快捷键。

我的脚本如下:

zhinput
#!/bin/bash -e
chars=$(zenity --title 中文输入 --text 中文输入 --width 500 --entry 2>/dev/null)
sleep 0.1
xdotool key --delay 150 Escape t
sleep 0.2
xdotool type --delay 150 "$chars"
xdotool key Return

原理很简单,在这个脚本被调用时,弹出一个对话框让用户输入文字。对话框关闭后,焦点应该回到 mc。发送 Escape 键「回到游戏」,然后发送「t」开启聊天。然后把文字发送过去并按回车。

很神奇,原来可以直接向它发送中文字符。不过那些延迟是需要的,不然会接收不完整。所以使用效果就是,对话框关闭之后,可以看到程序在往 mc 里一个个地输入文本并发送~

至于绑定快捷键,作为 Awesome 用户,可以做到只在 mc 的窗口绑定。定制性比较差的窗口管理器/桌面环境可能只能全局绑定了,会占用掉一个全局快捷键。

相关代码如下:

rc.lua (片断)
elseif c.class and c.class:match('^Minecraft ') then
local keys = c:keys()
local mykey = awful.key({'Control'}, 't', function(c)
awful.util.spawn('zhinput')
end)
keys = awful.util.table.join(keys, mykey)
c:keys(keys)
elseif c.name == '中文输入' then
awful.util.spawn_with_shell('sleep 0.05 && fcitx-remote -T', false)

顺便在弹出的对话框里把输入法切换到了中文模式~(完整的配置文件在这里


2019年01月02日更新:Minecraft 已经可以直接输入中文了(虽然有些类似于 teeworlds / DDNet 的 bug)。

发送到 Kindle


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK