|
本帖最后由 martin313 于 2025-2-21 15:47 编辑
以下是一个通过批处理调用 PowerShell 实现切换到 ENG 输入法的解决方案:
@echo off
powershell -Command "$sig = '[DllImport(\"user32.dll\")] public static extern IntPtr GetForegroundWindow(); [DllImport(\"user32.dll\")] public static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int lParam); [DllImport(\"user32.dll\")] public static extern IntPtr LoadKeyboardLayout(string pwszKLID, uint flags);'; Add-Type -MemberDefinition $sig -Name Keyboard -Namespace API; $hkl = [API.Keyboard]::LoadKeyboardLayout('00000409', 1); $hWnd = [API.Keyboard]::GetForegroundWindow(); [API.Keyboard]::PostMessage($hWnd, 0x50, 1, $hkl.ToInt32()); Start-Sleep -Milliseconds 200"
代码说明:
使用 PostMessage API 向当前窗口发送 WM_INPUTLANGCHANGEREQUEST 消息(0x50)
参数 0x0409 对应美式英语键盘布局(0409:00000409)
兼容 Windows 7 及以上系统,无需管理员权限
使用方法:
将代码保存为 SwitchToENG.bat
双击运行即可立即切换至 ENG 输入法
注意事项:
需确保 PowerShell 可正常使用(默认已启用)
若系统从未运行过 PowerShell 脚本,首次执行可能会有短暂延迟
切换效果对当前活动窗口立即生效 |
评分
-
查看全部评分
|