How do I continue sending keypress on an application even if it is not on focused using c#? - keypress

I would like to keep sending numbers from 1-5 in a notepad even if I am opening chrome or other applications.

Related

Can I force a windows 10/11 program to be unresponsive?

Is there anyway to set a program to be unresponsive in windows?
I have python code that starts a program. But when the program becomes unresponsive i want to do some specific clean up task.
But how do I test it. Because currently it is random.
Is there a way to either make a small program that I can force to be unresponsive?
Or force a running program to be unresponsive.
An "unresponsive" program is typically a GUI application that's blocked on it's main (UI) thread such that it hasn't pumped messages in a long time. That is, the UI feels "frozen" when you try to interact with it and/or the window doesn't seem to repaint itself as it should.
You can easily simulate this by creating a Windows Forms app in C# or Win32 GUI app in C++ using the default project templates in Visual Studio. Or basically any UI framework like Qt for that matter. Then introduce a very long sleep statement (several minutes) in response to a button click.
I don't think the "unresponsive" attribute applies to services, console applications, or background tasks.
Use Alt + Tab keyboard shortcut to bring your unresponsive program to the front, and then press Alt + F4 keys at the same time to force the program to quit.

Spy++ does not show me all Windows store app messages

When i use the window finder of spy++, i only get messages like WM_PAINT. Alot of messages are getting left out. I tried so far to select every window associated with the application and also processes and threads of the application.
It is working fine with apps that are not from the store.
is there any way to solve it ?

Windows: send Mouse/Keyboard event to background window?

My application is a fullscreen window which is rendering a designated other window (from dwm), for example Google Chrome. I would like to know if it's possible to send events (such as mouse keyboard events) to the specified window.
Of course the designated window has to stay in background, and my current application on the foreground.
My application is written in C++. I'm working on Windows 7/8.
Just to put it into an answer.
Based on this question Does any program/language/library that interacts with windows do it via the WIN32 API? you should be able to use the windows API to send a windows message to any window. All you need to get is that windows handle, or you could do a broadcast to all windows.
The specific function http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
Though that function will block until the windows responds and processes the message, this could hurt GUI performance. If you notice issues try implementing http://msdn.microsoft.com/en-us/library/windows/desktop/ms644951(v=vs.85).aspx instead.

How would i enable an unfocused window to still recieve event listeners?

I am working on a client-server application where the server will depending on buttons clicked, would fire all the events of a keyboard. It is limited to the keyboard as well.
I am making a custom keyboard for my left hand. A friend has only 1 hand so it similar would benefit him. They keyboard will be some sort of touch device, possibly a large tablet, which will through networking and port connections establish a connection with my server.
My server applcation (written in anything really, python, C, C++, java, I know a LOT of languages) will accept a flag, and then execute a set of commands.
Essentially i want to do something like:
if(key_pressed == 'f1')
execute the 'F1' key in focused window.
Server application is NOT focused and will be hidden, or minimized on screen.
Is there a way to go that without building custom drivers or something?
Edit:
Client is like having a keyboard
Server is like the driver. I want the server to fire off things as if it is a character device being manipulated. The thing i was looking into is that i was reading a post or 2 which said only focused applications receive presses, which is fine, i want them to execute in the focused window, but in the background, be a process which will catch and then carry out the signal wanted like in the key_pressed above

Is there a command line utility that can listen for OS-wide keystrokes and tell me via stdout?

I'm developing an app and I'd like to trigger functions in my app via keystroke combos when it's not in focus.
Because I'm developing my app in AIR, I do not have access to listen to global Keystrokes. However, I can receive STDOUT from an application. So, I'm looking for a utility that can give me this ability. I'm looking for both Windows and OSX (cross-platform baby!)
For Windows, you could write a simple application that installs a keyboard hook and prints information about the key event to stdout. See SetWindowsHookEx.
For Windows:
I don't know of any app off the top of my head, but here are some ideas that might work within 100 lines of code...
I would avoid SetWindowsHook, as that would inject your code into all apps. (Because I've spent good time debugging crash dumps and bugs as a result of poorly written hooks...)
You could write a console app with DirectInput (old gaming keyboard API). I believe you just pass DISCL_BACKGROUND and DISCL_NONEXCLUSIVE into IDirectInputDevice8::SetCooperativeLevel call. Use IDirectInputDevice8::SetEventNotification to set the event handle so you don't have get into a busy wait loop polling for input. And that should do it. I did this once for my app a long time ago on Windows 98 and it worked really well. But DirectInput is very close to being deprecated technology so YMMV.
Another simple hacked up way to do what you are doing is to have your app create a hidden window, call call RegisterHotkey for all the keyboard, and pump window messages. Your wndproc will get a WM_HOTKEY window message that you can use that to generate a message to stdout.
The simplest way, but will be slightly error prone and cpu-expensive is to have your console app get into a loop and call GetKeyboardState. This will return the entire state of the keyboard of all keys that are up and down. You'll have to figure out how translate each poll into a logical keystroke. I'd recommend sleeping a few milliseconds between polls so you don't kill system-wide performance.
Can't help you on OSX.
For windows, here is a utility that will listen to the keyboard.
http://www.dynamicnetservices.com/~will/academic/textinput/keycapture/

Resources