cute-jumper / fcitx-remote-for-windows

A fake fcitx-remote for Windows
23 stars 1 forks source link

3种语言的切换 #3

Open perfectkaki opened 1 year ago

perfectkaki commented 1 year ago

这个有没有可能扩展到3种语言的切换。

例如实现目标:

  1. 使用英文, 中文,日语输入法。(切换时候的排序为 英,中,日)
  2. 输入命令时候, 全部切换至英文
  3. 命令输入完毕后,切换回来的输入法。

在原有的代码下,我进行了尝试, 一句一句的查代码的意思,憋了2周,只实现到了第二步。能不能指点下(=-=) 下面是我尝试的代码(把里面的一个叫fcitx-remote.cpp的文件修改了)。

include "stdafx.h"

include

include

pragma comment(lib, "user32.lib")

include

using namespace std;

BOOL toggleInputMethod() { INPUT ips[4]; memset(ips, 0, sizeof(ips)); for (int i = 0; i < 4; i++) { ips[i].type = INPUT_KEYBOARD; } // uncomment if use win+space //ips[0].ki.wVk = ips[2].ki.wVk = VK_LWIN; //ips[1].ki.wVk = ips[3].ki.wVk = VK_SPACE; ips[0].ki.wVk = ips[2].ki.wVk = VK_MENU; ips[1].ki.wVk = ips[3].ki.wVk = VK_SHIFT; ips[2].ki.dwFlags = ips[3].ki.dwFlags = KEYEVENTF_KEYUP; SendInput(4, ips, sizeof(INPUT)); return 0; }

static int layout_num = 0;

int _tmain(int argc, _TCHAR* argv[]) { HKL currentLayout = GetKeyboardLayout(0); if (argc > 1) { if (!_tcscmp(argv[1], _T("-c"))) { //english layout if (currentLayout == LoadKeyboardLayout((LPCWSTR)L"00000409", KLF_ACTIVATE)) { layout_num = 0; } //Cn layout else if (currentLayout == LoadKeyboardLayout((LPCWSTR)L"00000804", KLF_ACTIVATE)) { toggleInputMethod(); toggleInputMethod(); layout_num = 1; } //Jp layout else if (currentLayout == LoadKeyboardLayout((LPCWSTR)L"00000411", KLF_ACTIVATE)) { toggleInputMethod(); layout_num = 2; } else { // printf ("unknown\n"); } } else if (!_tccmp(argv[1], _T("-o"))) { if (layout_num == 0) { } else if (layout_num == 1) { toggleInputMethod();
} else if (layout_num == 2) { toggleInputMethod(); toggleInputMethod();
} } } else { cout << (2 - (currentLayout == LoadKeyboardLayout((LPCWSTR)L"00000409", KLF_ACTIVATE))) << endl; } return 0; }

Tyushang commented 10 months ago

就目前的框架来说, 你这个需求很难实现, 分析如下: