gpt4 book ai didi

c# - TabTip 键盘 c# 的设置位置不起作用

转载 作者:行者123 更新时间:2023-11-30 18:29:39 25 4
gpt4 key购买 nike

我试图重新定位 TabTib 键盘但没有成功,SetWindowPos 函数返回“True”但键盘没有移动。我在 Windows 7 上使用 C#。

` [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    [DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
int Y, int cx, int cy, uint uFlags);

[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string ClassName, string WindowName);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}

Rectangle KeyboardRect;
IntPtr TabTipHandle;

IntPtr GetWindowHandle()
{
return FindWindow("IPTip_Main_Window",null);
}

bool MoveKeyBoard(IntPtr hWnd, int ToX, int ToY)
{
return SetWindowPos(hWnd, this.Handle, ToX, ToY, KeyboardRect.Width, KeyaboardRect.Height, 0x0045);
}
void StartKeyboard()
{
Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
TabTipHandle = GetWindowHandle();
KeyboardRect = GetKeyboardRect(TabTipHandle);
textBox1.Text = KeyaboardRect.Top.ToString() + ", " + KeyboardRect .Left.ToString() + ", " + KeyboardRect .Width.ToString() + ", " + KeyboardRect .Height.ToString();

MoveKeyBoard(TabTipHandle, 100, 100);
KeyboardRect = GetKeyboardRect(TabTipHandle);
textBox2.Text = KeyaboardRect.Top.ToString() + ", " + KeyboardRect .Left.ToString() + ", " + KeyboardRect .Width.ToString() + ", " + KeyboardRect .Height.ToString();
}
void button1_Click(object sender, EventArgs e)
{
StartKeyboard();
}
void button2_Click(object sender, EventArgs e)
{
MoveKeyBoard(TabTipHandle, 200, 100);
KeyboardRect = GetKeyboardRect(TabTipHandle);
textBox2.Text = KeyboardRect .Top.ToString() + ", " + KeyboardRect .Left.ToString() + ", " + KeyboardRect .Width.ToString() + ", " + KeyboardRect .Height.ToString();

}

`

最佳答案

如果您在创建流程后稍作延迟,它将起作用:

 Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
await Task.Delay(150); // Just a tiny delay before continuing
...
MoveKeyBoard(TabTipHandle, 100, 100);
...

但是现在我遇到了一个奇怪的问题,即使用 SetWindowPos 时键盘不会准确地定位在我想要的位置。窗口似乎围绕该点摆动,直到多次调用 SetWindowPos 后它才保持不动。很奇怪,如果你问我的话。由于缺少任何文档,我搜索了注册表,因为我注意到 TabTip.exe 将在它关闭的完全相同的位置启动。所以我找到了这两个 DWORD 注册表值:

HKCU\SOFTWARE\Microsoft\TabletTip\1.7\OptimizedKeyboardRelativeXPositionOnScreen
HKCU\SOFTWARE\Microsoft\TabletTip\1.7\OptimizedKeyboardRelativeYPositionOnScreen

我对这些值进行了试验,似乎在开始该过程之前将两者都设置为 50000 会将键盘的左上角定位到屏幕中央。将两者都设置为 0 会将其准确定位在左上角,而将两者都设置为 100000 则相应地表示右上角。

关于c# - TabTip 键盘 c# 的设置位置不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22630783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com