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.

Disable back

Post Reply
dinko
Posts: 15
Joined: Mon Jan 28, 2019 8:44 am

Disable back

Post by dinko »

Is there any way to completely disable back ? My main problem is user pressing mouse's back button and I want to avoid as the page is in a kiosk system.

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

Re: Disable back

Post by salvadordf »

Hi,

I don't have navigation buttons in my mouse and I can't test it but try this :
https://www.briskbard.com/forum/viewtop ... 826&p=3689
dinko
Posts: 15
Joined: Mon Jan 28, 2019 8:44 am

Re: Disable back

Post by dinko »

Thanks! After reading everything, I found the best way to completely disable in Delphi level


hkk := SetWindowsHookEx(WH_MOUSE_LL, @MouseHook, 0, 0);

...

function MouseHook(code: Integer; wparam: WPARAM; lparam: LPARAM): LRESULT; stdcall;
var
a: TMOUSEHOOKSTRUCT;
begin
if code < 0 then
Result := CallNextHookEx(hkk,code,wparam,lparam)
// discard all right button related mouse messages
else if (wParam = WM_MBUTTONDOWN) or (wParam = WM_XBUTTONUP) or (wParam = WM_XBUTTONDOWN) then
Result := 1
else
Result := 0;
end;
dinko
Posts: 15
Joined: Mon Jan 28, 2019 8:44 am

Re: Disable back

Post by dinko »

@salvadordf,

i have a small problem with this approach. It totally blocks mouse buttons in the entire system not only in my app.
I found out that

hkk := SetWindowsHookEx(WH_MOUSE_LL, @MouseHook, HInstance, 0);

has to change to

hkk := SetWindowsHookEx(WH_MOUSE_LL, @MouseHook, HInstance, GetCurrentThreadID);

But now buttons work both in my app and in global. It looks like GetCurrentThreadID is wrong because chromium has its own thread id, am I wrong? How should I found out the chromium thread id so I can hook only to this window?

I load it as single process

GlobalCEFApp.SingleProcess := true;

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

Re: Disable back

Post by salvadordf »

Try blocking the message only if your application is focused.
https://stackoverflow.com/questions/371 ... -has-focus

Please, use the SingleProcess mode only for debugging purposes. It's a known cause of unexpected errors.
dinko
Posts: 15
Joined: Mon Jan 28, 2019 8:44 am

Re: Disable back

Post by dinko »

Yes I know Single Process causes problems dont worry.
And I know how to check for my focus, but I still want to ask if not possible to get chromium thread id?
User avatar
salvadordf
Posts: 4565
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Disable back

Post by salvadordf »

I'm not sure what Chromium thread would be used for this.
I guess that the thread referenced as UI by the CEF documents would be a good candidate.

A simple way to get that ID would be to call "GetThreadID" inside any TChromium event that is executed in that thread, for example TChromium.OnAfterCreated.

Chromium creates many more threads as you can see in the debugger or in the "Sysinternals Process Explorer"
Post Reply