How to position the On-Screen Keyboard window?

╄→尐↘猪︶ㄣ 提交于 2019-12-10 21:04:49

问题


After launching osk.exe with ShellExecuteEx() I would like to position the keyboard window relative to the data-entry fields, so that it doesn't cover them.

How do I set the window position for the osk before calling it?

Also, how can I have the application hide the osk when I am finished?


回答1:


You can use FindWindow using the window class "OSKMainClass" to get the window handle, and then SetWindowPos on that handle to position it to the coordinates you want. (You may need to use the control's ClientToScreen method to convert to the proper coordinates, but I'll let you figure that part out.)

// Off the top of my head - not at a machine that has a Delphi compiler at
// the moment.
var
  OSKWnd: HWnd;
begin
  OSKWnd := FindWindow(PChar('OSKMainClass'), nil);
  if OSKWnd <> 0 then
  begin
    SetWindowPos(OSKWnd, 
                 HWND_BOTTOM, 
                 NewPos.Left, 
                 NewPos.Top, 
                 NewPos.Width,
                 NewPos.Height, 
                 0);
  end;
end;

Code taken in part from a CodeProject article related to the same topic. I got the window class using AutoHotKey's Window Spy utility.

Notes:

  1. Remy Lebeau points out in a comment that you should make sure to use CreateProcess() or ShellExecuteEx() so that you get back a process handle that can then be passed to WaitForInputIdle() before calling FindWindow(). Otherwise the call to FindWindow() may happen before OSK creates the window.

  2. mghie points out in a comment that the only way he could get this to work was by running the app as Administrator; otherwise the call to SetWindowPos() resulted in an "Access Denied (5)".




回答2:


I can,t move the window as mentioned above. Using Win32 commands, SetWindow or MoveWindow not worked for on screen keyboard. Its worked only while running exe in admin privilege.

I think its not a good solution. I found another solution. Please go through this. After trying using registry values its worked well i can move on screen keyboard in my application

try

                               {

                               RegistryKey myKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Osk", true);

                               myKey.SetValue("WindowLeft", oskLeft, RegistryValueKind.DWord);
                               myKey.SetValue("WindowTop", oskTop, RegistryValueKind.DWord);


                               }

                               catch

                               {

                                        //Log the error
                               }


来源:https://stackoverflow.com/questions/24707902/how-to-position-the-on-screen-keyboard-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!