C
C#4mo 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
canton74mo ago
What messages do you expect it to receive when it's not focussed?
Pandetthe
Pandetthe4mo ago
From Wintab API
canton7
canton74mo 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
Pandetthe4mo ago
I have indepented stylus writing and mouse usage
canton7
canton74mo ago
"indepented"?
Pandetthe
Pandetthe4mo ago
I mean you can use mouse and stylus in the same time And problem starts when somebody select with mouse another app
canton7
canton74mo 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
Pandetthe4mo 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
canton74mo 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
Pandetthe4mo ago
I was testing some time ago some Wacom sdk and it was working
canton7
canton74mo ago
Windows doesn't know whether it's sending messges to a message pump which is being operated from windows or WPF
Pandetthe
Pandetthe4mo ago
I know I found today something named message-only window Maybe it would work
Jester
Jester4mo 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
Jester4mo 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
Jester4mo ago
@Pandetthe
Pandetthe
Pandetthe4mo ago
Thanks, I found another solution based on wintab api
Want results from more Discord servers?
Add your server
More Posts