【发布时间】:2013-07-03 04:30:11
【问题描述】:
当文本框获得焦点时,我正在运行虚拟键盘,但随后键盘应用程序获得焦点并且不会将键传输到文本框。 如果我点击文本框来激活它,一切都很好,但我希望我的应用程序在 vKeyboard 进程运行后被激活。 这是我迄今为止尝试过的:
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
....
vKeyboard = Process.Start(keyboardPath);
SetFocusToApplication(handle);
....
private static void SetFocusToApplication(IntPtr handle)
{
Process currentProcess = Process.GetCurrentProcess();
IntPtr hWnd = currentProcess.MainWindowHandle;
if (hWnd != IntPtr.Zero)
{
SetForegroundWindow(handle);
ShowWindow(hWnd,3);
}
}
我也尝试将 Alt + Tab 发送到键盘进程,但它不起作用:
private static void AltTab(IntPtr handle)
{
vKeyboard.WaitForInputIdle();
int WM_SYSCOMMAND = 0x0112;
int SC_PREVWINDOW = 0xF050;
PostMessage(vKeyboard.MainWindowHandle, WM_SYSCOMMAND, (IntPtr)SC_PREVWINDOW, (IntPtr)0);
}
PS:我确实有虚拟键盘的源代码,如果我可以从那里做任何事情来停用它自己,仍然可以。让我知道。 键盘最顶部的属性也设置为 true,不确定这是否有任何不同。
这是我正在尝试并在按钮单击中起作用的代码:
Process vKeyboard;
string keyboardPath = Application.StartupPath + "\\vKeyboard.exe";
vKeyboard = Process.Start(keyboardPath);
【问题讨论】:
-
您是否编写了虚拟键盘并可以访问源代码?
-
是的,我可以访问虚拟键盘源代码。
-
您为什么要编写自己的虚拟键盘,而不是使用所有版本的 Windows 中包含的屏幕键盘?它经过充分测试,完全不会引起关注。
-
我想要一个没有 ESC 和 Win 键以及一些附加键的键盘。它适用于自助服务终端应用程序,因此必须手动制作。
标签: c# .net process activation