TL; DR :尝试解决InputLanguage更改input布局但不更新语言栏显示的问题。
我正在为Trados Studio编写一个自定义插件。 其中的一部分是与应用程序本身和Word中的语言进行交互,就像这个问题一样: Windows .NET框架的所有可用语言列表
我似乎无法解决的最后一个问题是,在我使用InputLanguage设置键盘inputen-US的代码的一部分。
要说明的是, API是有限的,所以我必须在某些方面实现自动化。 最好的方法是在应用程序中使用默认的快捷方式:
Windows / C#通过操作系统(而不是IP地址)检测用户的半球?
在compmgmt.msc中显示的文件监视文件上的windows #locks
哪里可以放置普通用户数据而没有pipe理权限?
为Windows服务设置环境variables
首先,我将input语言改为en-US。
然后我发送一些密钥给应用程序。
然后我将input语言改回原来的样子。
这里是代码:
//change input language to English InputLanguage currentLang = InputLanguage.CurrentInputLanguage; InputLanguage newLang = InputLanguage.FromCulture(System.Globalization.CultureInfo.GetCultureInfo("en-US")); if (newLang == null) { MessageBox.Show("The Upload Project function requires the En-US keyboard installed.","Missing keyboard",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); return; } else { InputLanguage.CurrentInputLanguage = newLang; } //Save the document SendKeys.SendWait("^s"); InputLanguage.CurrentInputLanguage = currentLang; //get url and credentials from a custom input form string[] psw = UploadData.getpassword( Settings.GetValue("Upload","Uri","https://www.scntranslations.org/ws/services"),Vars.wsUsername == null ? Settings.GetValue("Upload","User","") : Vars.wsUsername,Vars.wsPassword == null ? "" : Vars.wsPassword ); Application.DoEvents();
我的performance就是,语言栏会随着EN延迟而改变,但在表单显示时,它应该是HU,但它仍然保持EN 。
但是,如果我testing它与Debug.WriteLine(InputLanguage.CurrentInputLanguage.LayoutName)然后输出是正确的语言(在我的情况下“匈牙利”)。
即使在表单隐藏之后,语言仍然是EN ,但匈牙利语的键盘types和Debug.WriteLine(InputLanguage.CurrentInputLanguage.LayoutName)返回“匈牙利语”。
我看了很多网页和网页,我尝试了所有我能想到的,包括System.Threading.Thread.Sleep(1000); 和Application.DoEvents()和Sendkeys.Flush() ,但没有触发Windows更新语言栏,我找不到任何解决此问题。
此问题中给出的此问题的早期版本: 从.NET 4.5.2 C#代码中更改键盘布局
现在我已经完成了上面这个最后一步的InputLanguage栏的实现。
任何人都可以帮忙:
给出这种行为的解释?
更新:代码现在完全工作。 我实现了BlockInput WinAPI。
[System.Runtime.InteropServices.DllImportAttribute("user32.dll",EntryPoint = "BlockInput")] [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] public static extern bool BlockInput([System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] bool fBlockIt);
还要使用Win APIclosuresCaps Lock:
[DllImport("user32.dll")] public static extern void keybd_event(byte bVk,byte bScan,uint dwFlags,UIntPtr dwExtraInfo); private void TurnOffCapsLock() { if (Control.IsKeyLocked(Keys.CapsLock)) // Checks Capslock is on { const int KEYEVENTF_EXTENDEDKEY = 0x1; const int KEYEVENTF_KEYUP = 0x2; NativeMethods.keybd_event(0x14,0x45,KEYEVENTF_EXTENDEDKEY,(UIntPtr)0); NativeMethods.keybd_event(0x14,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,(UIntPtr)0); } }
所以剩下的就是让语言栏正确显示当前的input语言。
我可以select发送Alt + Shifts,但我真的不想这么做。
当创build一个新线程时,对GUI的更改没有被制作(C#)
Windows资源pipe理器在应用程序调用Web服务时不响应
你如何处理开发人员访问Windows服务器?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。