C
C#9mo ago
Pandetthe

✅ Wndproc is not receiving any messages when window is not focused

HI! I am trying to handle messages in WPF using WndProc like this:
_messageWindowHandle = new WindowInteropHelper(window).EnsureHandle();
HwndSource.FromHwnd(_messageWindowHandle).AddHook(WndProc);
_messageWindowHandle = new WindowInteropHelper(window).EnsureHandle();
HwndSource.FromHwnd(_messageWindowHandle).AddHook(WndProc);
When window is focused everything is working fine, but when I select another window, wndproc stop receiving any messages. How can I fix it?
16 Replies
canton7
canton79mo ago
What messages do you expect it to receive when it's not focussed?
Pandetthe
PandettheOP9mo ago
From Wintab API
canton7
canton79mo ago
The Windows Ink thing? Why would that send you messages about what the stylus is doing when you're not the focussed application?
Pandetthe
PandettheOP9mo ago
I have indepented stylus writing and mouse usage
canton7
canton79mo ago
"indepented"?
Pandetthe
PandettheOP9mo ago
I mean you can use mouse and stylus in the same time And problem starts when somebody select with mouse another app
canton7
canton79mo ago
I still don't follow. Windows has the concept of there being a single focussed application, which receives things like mouse movements and keyboard inputs. If you start typing, you don't want all of your windows to start responding to key presses. Likewise if you click on a window, you don't want the windows behind it to respond to the click
Pandetthe
PandettheOP9mo ago
Imagine it this way, you have a main screen on which you are doing something and an additionally connected tablet with a screen. The application I am talking about is displayed on the tablet screen. On tablet screen there is no other window. I know that I can get all the messages using winforms in the background but I am looking for less overcomplicated solution without using wpf and winforms at the same time
canton7
canton79mo ago
The message loop in winforms and WPF should be the same? I've done some googling, and I've yet to find a resource saying that two windows can receive input events at the same time in Windows Have you seen anything which suggests this is possible?
Pandetthe
PandettheOP9mo ago
I was testing some time ago some Wacom sdk and it was working
canton7
canton79mo ago
Windows doesn't know whether it's sending messges to a message pump which is being operated from windows or WPF
Pandetthe
PandettheOP9mo ago
I know I found today something named message-only window Maybe it would work
Jester
Jester9mo ago
only the focused window gets window input messages. but if you want to get window input messages even if ur not the focused window. you can use lowlevel hooks or rawinput
Jester
Jester9mo ago
bcuz people ask for this frequently, i have made an example project https://github.com/QubitTooLate/Keylogging
GitHub
GitHub - QubitTooLate/Keylogging: Useful wrapper for Hot Keys and R...
Useful wrapper for Hot Keys and Raw Input in C#. Contribute to QubitTooLate/Keylogging development by creating an account on GitHub.
Jester
Jester9mo ago
@Pandetthe
Pandetthe
PandettheOP9mo ago
Thanks, I found another solution based on wintab api
Want results from more Discord servers?
Add your server