Recent

Author Topic: Triggering the On Screen Keyboard  (Read 641 times)

geraldholdsworth

  • Full Member
  • ***
  • Posts: 226
Triggering the On Screen Keyboard
« on: February 01, 2025, 12:30:40 pm »
I'm developing an application to be used on a Windows 11 tablet. This application has TEdit components for data entry, but when I tap on one the Windows On Screen Keyboard doesn't pop up.

Is there a way of activating it?

This is Lazarus 2.2.6 on Windows 10 (but developing for 11) 64 bit. FPC is the standard install that came with it (not sure on the version).

PascalDragon

  • Hero Member
  • *****
  • Posts: 5940
  • Compiler Developer
Re: Triggering the On Screen Keyboard
« Reply #1 on: February 02, 2025, 10:02:44 pm »
The following works for me in a quick test on a Windows 10 in tablet mode (found here):

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Edit1: TEdit;
  17.     procedure Edit1Enter(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. uses
  30.   Windows;
  31.  
  32. {$R *.lfm}
  33.  
  34. function FindTrayButtonWindow: THandle;
  35. var
  36.   ShellTrayWnd: THandle;
  37.   TrayNotifyWnd: THandle;
  38. begin
  39.   Result := 0;
  40.   ShellTrayWnd := FindWindow('Shell_TrayWnd', nil);
  41.   if ShellTrayWnd > 0 then
  42.   begin
  43.     TrayNotifyWnd := FindWindowEx(ShellTrayWnd, 0, 'TrayNotifyWnd', nil);
  44.     if TrayNotifyWnd > 0 then
  45.     begin
  46.       Result := FindWindowEx(TrayNotifyWnd, 0, 'TIPBand', nil);
  47.     end;
  48.   end;
  49. end;
  50.  
  51.  
  52. { TForm1 }
  53.  
  54. procedure TForm1.Edit1Enter(Sender: TObject);
  55. var
  56.   TrayButtonWindow: THandle;
  57. begin
  58.   TrayButtonWindow := FindTrayButtonWindow;
  59.   if TrayButtonWindow > 0 then
  60.   begin
  61.     PostMessage(TrayButtonWindow, WM_LBUTTONDOWN, MK_LBUTTON, $00010001);
  62.     PostMessage(TrayButtonWindow, WM_LBUTTONUP, 0, $00010001);
  63.   end else begin
  64.     ShellExecute(0, 'open', 'c:\Program Files\Common Files\microsoft shared\ink\TabTip.exe', nil, nil, SW_SHOWNA);
  65.   end;
  66. end;
  67.  
  68. end.

Note: I added the button with TabOrder set to 0 so that the edit control wouldn't start selected.

geraldholdsworth

  • Full Member
  • ***
  • Posts: 226
Re: Triggering the On Screen Keyboard
« Reply #2 on: February 03, 2025, 02:25:18 pm »
Works perfectly.

Thank you.

 

TinyPortal © 2005-2018