Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

OnScreen Keyboard won't type

User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OnScreen Keyboard won't type

Post by salvadordf »

I uploaded a new version of the SimpleOSRBrowser demo with a TTouchKeyboard that is shown when you click the "keyboard" button in the top-right corner of the demo.

The SimpleOSRBrowser demo uses the OSR mode. This mode is more complicated but it allows you to control and simulate all keyboard and mouse events.

This is just a quick workaround. I guess you can hide and show the touch keyboard automatically checking the cursor in TChromium.OnCursorChange

If you don't like TTouchKeyboard you can use the virtual keyboard included in Windows following these instructions :
https://stackoverflow.com/questions/387 ... n/40921638
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OnScreen Keyboard won't type

Post by salvadordf »

About reducing the CEF3 features, all you can do is disable some of them using the GlobalCEFApp and TChromium properties.
You can try disabling everything you don't use but I don't think that will help you with this bug.
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: OnScreen Keyboard won't type

Post by Hitman »

Hi!
Thank you!!
yes!
the new demo seems to work without crashing and my own keyboard works as well Image
I will start making my browser accordingly.

Many thanks Salvador!!
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: OnScreen Keyboard won't type

Post by Hitman »

Hi Salvador!
re-created the browser by following your last OSR demo and here is the result :(
- Browser cannot be closed, it is crashing whenever i try to close it. It gives not responding error
- I cannot type anything by using my own keyboard, it crashes the soon i try to type something

OSR demo works as it is but i need to add some other things to make it work as required.

I am hoping you could tell what am i doing wrong or,
1) Perhaps you could tell me how can i terminate the OSR demo by using VK_ESCAPE with out crashing?
2) I am using a timer to calculate x minutes and reload the default url if user is idle for those x minutes

These 2 options are the things i need first to be able to terminate it because the border style of my browser form is set to bsNone and there is nothing to click for closing it.

I am using the following for reloading the browser if user is idle for 3 minutes,
First the idle time code,

Code: Select all

{ - <<< - [ user idle time events for reloading... ] - >>> - }
procedure TfrmMain.timerIdleTimeTimer(Sender: TObject);
var
  vIdleTime: Cardinal;
  vHours: Cardinal;
  vMinutes: Cardinal;
  vSeconds: Cardinal;
begin
  { calculate the idle time. It's in milliseconds }
  vIdleTime := GetTickCount - FStartIdle;

  { get how many hour has the user been idle }
  vHours := vIdleTime div (60 * 60 * 1000);
  if vHours > 0 then
    vIdleTime := vIdleTime - (vHours * 60 * 60 * 1000);

  { get the minutes part of the time the user been idle }
  vMinutes := vIdleTime div (60 * 1000);
  if vMinutes > 0 then
    vIdleTime := vIdleTime - (vMinutes * 60 * 1000);

  { get the seconds part of the time the user been idle }
  vSeconds := vIdleTime div 1000;

  { Show the duration of time user has been idle }
  frmRequired.labelIdleTime.Caption := Format('%.2d:%.2d:%.2d',
    [vHours, vMinutes, vSeconds]);
end;
and than the following timers for reloading the browser when user is idle,

Code: Select all

{ - <<< - [ refresh the web page if idle for 3 minutes... ] - >>> - }
procedure TfrmMain.timerRefreshTimer(Sender: TObject);
begin
  if frmRequired.labelIdleTime.Caption = '00:03:00' then
  begin
    { clear history and cache }
    chromiumMain.CustomHeaderName := 'Cache-Control';
    chromiumMain.CustomHeaderValue := 'no-cache';
    { reload browser }
    chromiumMain.LoadURL(frmRequired.leditUserInterface.text);

    { close if on-screen keyboard is active }
    if frmRequired.checkboxKeyboardStatus.Checked then
      CloseOnScreenKeyboard;
  end;
end;

{ - <<< - [ send refresh request... ] - >>> - }
procedure TfrmMain.timerSendRefreshTimer(Sender: TObject);
begin
  if frmRequired.labelIdleTime.Caption = '00:03:05' then
    timerIdleTime.Enabled := False;
end;
The URL is a user interface which is used by people and i need to make sure it goes to the main page when no one is using it and has been left at some stage.
If i can make these 2 work in OSR browser,
everything will be just fine.

Many thanks in advance
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: OnScreen Keyboard won't type

Post by salvadordf »

Hitman wrote: Fri Aug 03, 2018 3:55 pm Hi Salvador!
re-created the browser by following your last OSR demo and here is the result :(
- Browser cannot be closed, it is crashing whenever i try to close it. It gives not responding error
- I cannot type anything by using my own keyboard, it crashes the soon i try to type something

OSR demo works as it is but i need to add some other things to make it work as required.

I am hoping you could tell what am i doing wrong or,
1) Perhaps you could tell me how can i terminate the OSR demo by using VK_ESCAPE with out crashing?
2) I am using a timer to calculate x minutes and reload the default url if user is idle for those x minutes
To close the app you need to send a WM_CLOSE message to the form. If you used the SimpleOSRBrowser as a template for your app, modify the AppEventsMessage procedure. Scroll to the section where it detects WM_CHAR and replace it with this :

Code: Select all

    WM_CHAR :
      if Panel1.Focused then
        begin
          if (Msg.wParam = VK_ESCAPE) then
            begin
              PostMessage(Handle, WM_CLOSE, 0, 0);
              exit;
            end;

          TempKeyEvent.kind                    := KEYEVENT_CHAR;
          TempKeyEvent.modifiers               := GetCefKeyboardModifiers(Msg.wParam, Msg.lParam);
          TempKeyEvent.windows_key_code        := Msg.wParam;
          TempKeyEvent.native_key_code         := Msg.lParam;
          TempKeyEvent.is_system_key           := ord(False);
          TempKeyEvent.character               := #0;
          TempKeyEvent.unmodified_character    := #0;
          TempKeyEvent.focus_on_editable_field := ord(False);

          chrmosr.SendKeyEvent(@TempKeyEvent);
          Handled := True;
        end;
Please, read the comments in the uSimpleOSRBrowser.pas file. To close the OSR demo you need to follow these steps :
  • FormCloseQuery sets CanClose to the initial FCanClose value (False) and calls chrmosr.CloseBrowser(True).
  • chrmosr.CloseBrowser(True) will trigger chrmosr.OnClose and we have to set "Result" to false and CEF3 will destroy the internal browser immediately.
  • chrmosr.OnBeforeClose is triggered because the internal browser was destroyed. Now we set FCanClose to True and send WM_CLOSE to the form.
Make sure that FormCloseQuery, chrmosrClose and chrmosrBeforeClose are present and have the same code as the demo.

To detect when your app is idle you can use these examples :
http://delphitipsandtricks2.blogspot.co ... -time.html
https://stackoverflow.com/questions/406 ... not-in-use
Hitman
Posts: 73
Joined: Sat May 20, 2017 11:08 am

Re: OnScreen Keyboard won't type

Post by Hitman »

THANK YOU!!!!!! :D :D :D :D :D :D
Extremely appreciated!

It now all seems to work!
I have kept my own Idle time procedure which seems to work fine and keyboard also seems to work.

Many thanks Salvador!
Post Reply