Systemwide event handler through callback

Just starting out? Need help? Post your questions and find answers here.
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

Systemwide event handler through callback

Post by LiK137 »

Hi,
I'm searching for possibility for handling events even
1. window is invisible
2. window is small size
3. focus outside of window

When window is visible or Width & Height greater 0 then events handled but not otherwise.

Many thanks for any hints.
User avatar
mk-soft
Always Here
Always Here
Posts: 5338
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Systemwide event handler through callback

Post by mk-soft »

If a window is not active, there are no events for the window to process. This is normal and comes from the operating system.

Explain what events should come?
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 5338
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Systemwide event handler through callback

Post by mk-soft »

If a window is not active, there are no events for the window to process. This is normal and comes from the operating system.

Explain what events should come?

If you want to process something in the event loop that is not an event, there are three possibilities.

1: WaitWindowEvent([Timeout]). All events must be filtered.
2: SetWindowTimer
3: Threads
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Systemwide event handler through callback

Post by firace »

Something like this? (just a quick example)
Run the code then press Ctrl+F10 to trigger an event

Code: Select all

RegisterHotKey_(0, 0, #MOD_CONTROL , #VK_F10)


OpenWindow(0, 100, 100, 140, 80, "",  #PB_Window_Invisible)



Repeat
  ev=WaitWindowEvent()
  If ev=#WM_HOTKEY
    OpenWindow(1, 100, 100, 240, 80, "Hotkey detected")
    
  EndIf
Until ev=#PB_Event_CloseWindow
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

Re: Systemwide event handler through callback

Post by LiK137 »

Thanks mk-soft and firace.
The events fired from device driver. Windowed program normally intercepts them throw callback or waitwindowevents. But windowless handling events through thread like a Windows Service becomes impossible.
That's why I create such question and ask for help.
User avatar
mk-soft
Always Here
Always Here
Posts: 5338
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Systemwide event handler through callback

Post by mk-soft »

If the driver sends window messages to your program, see PB-Help SetWindowCallback.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

Re: Systemwide event handler through callback

Post by LiK137 »

OK when use setwindowcalback with or without windowID in argument but only with visible window.
What about invisible window?
User avatar
mk-soft
Always Here
Always Here
Posts: 5338
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Systemwide event handler through callback

Post by mk-soft »

Do not include a WindowID.

The SetWindowCallBack is always processed before the PB WaitWindowEvent. This is the direct interface of the messages from the operating system to your programme.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

Re: Systemwide event handler through callback

Post by LiK137 »

Hmm, then what is the problem events not handled on window hidden.
I use SetWndCallback with no windowID and not receive messages. May be I should use WindowTimer to force fire timer messages. Right now I'm unable to test as device should be attached for using driver. How do you think, timer could solve the problem?
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: Systemwide event handler through callback

Post by Bisonte »

The short one :

it does not matter whether a window is visible or not. The main thing is that it is defined.

The procedure that you include via SetWindowcallback is always processed first ( before PB gets the events ), so if events arrive from the operating system, you can process them there.

If you specify the window number with SetWindowCallback as a parameter, it applies only to the given window. If not, then the Callback is set for all windows that you have created with PB in this program.
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

Re: Systemwide event handler through callback

Post by LiK137 »

There is only 1 window which is hidden.
Post Reply