[DllImport (" User32. DLL, "EntryPoint=" FindWindow ")]
Public extern static IntPtr FindWindow (string lpClassName, string lpWindowName);
[System. The Runtime. InteropServices. DllImportAttribute (" user32. DLL EntryPoint="MoveWindow")]
Public static extern bool MoveWindow (System. IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport (" user32. DLL)]
The static extern bool SetForegroundWindow (IntPtr hWnd);
[DllImport (" kernel32. DLL, "SetLastError=true)]
Public static extern bool Wow64DisableWow64FsRedirection (ref IntPtr PTR);
[DllImport (" kernel32. DLL, "SetLastError=true)]
Public static extern bool Wow64RevertWow64FsRedirection IntPtr (PTR);
Private System. Diagnostics. Process softKey.
Then start code below
Private void button1_Click (object sender, EventArgs e)
{
//open the soft keyboard
Try
{
IntPtr PTR=new IntPtr ();
Bool isWow64FsRedirectionDisabled=Wow64DisableWow64FsRedirection (ref PTR);
If (isWow64FsRedirectionDisabled)
{
SoftKey=System. Diagnostics. Process. The Start (@ "C: \ WINDOWS \ system32 \ osk exe");
Bool isWow64FsRedirectionReverted=Wow64RevertWow64FsRedirection (PTR);
}
//the above statements, after open the soft keyboard system also useless immediately put the soft keyboard window is created, so the following code to use loop to query window is created, only to create a window
//FindWindow to find the window handle, can only move the position of the window and set the size of the window, here is the key,
IntPtr IntPtr=IntPtr. Zero;
While (IntPtr. Zero==IntPtr)
{
System. Threading. Thread. Sleep (100);
Intptr=FindWindow (null, "on-screen keyboard");
}
//get the screen size
Int iActulaWidth=Screen. PrimaryScreen. Bounds. Width;
Int iActulaHeight=Screen. PrimaryScreen. Bounds. Height;
//set the display position of soft keyboard, centered at the bottom of the
Int posX=(iActulaWidth - 1000)/2;
Int posY=(iActulaHeight - 300);
//set the keyboard display position
MoveWindow (intptr, posX and posY, 1000, 300, true);
//set the soft keyboard to the front-end display
The SetForegroundWindow (intptr);
}
The catch (System. Exception ex)
{
MessageBox. Show (ex. Message);
}
}
Soft keyboard handle intptr can get, but unable to move, but change the form of findwindow seeking to "calculator", can move smoothly, other forms can be moved, only soft keyboard can't move
Does excuse me permission problems or soft keyboard form caused by the front
Is there any way can let win10 system under the position of the soft keyboard in want
CodePudding user response:
The soft keyboard is not to play with you...If there is no input requirement, I recommend using their own soft keyboard, see [sketchpunk/openkeyboard: Virtual the rid_device_info_keyboard with dynamic user defined layouts] (https://github.com/sketchpunk/openkeyboard)