I want to send an Application Key Presses, To Automate some stuff that has to be done repeatedly and So I don't always have to cramp my fingers.
In C#, it's nice to use SendKeys.Send(), but this won't work because the Application doesn't take Windows Messages. SendKeys.SendWait() does nothing at all.
How would I STILL Simulate the Keyboard events?
Come To Think of It, I was going to use some P/Invoke to simulate Mouse Events too, but If it takes no messages, How Can I get around that?
EDIT - I can use mouse and keyboard to interact with the program, I just cannot manipulate it with Windows Messages sent from my own Code.
Have you tried AutoIt?
Is it a console app? If so, maybe you should be SendKeys'ing to the command shell instance it is running in.
Related
I have an application where I have multiple keyboards connected through USB.
I need to hook a specific keyboard to get the keypress directly into the software, even if this one is not on the foreground. This so far works based on this project. The other keyboards shall work as normal.
Although it seems by using Direct Input, it is not possible to stop propagation (we don't want other apps to get that particular keyboard input).
Concerning Global Hook, it can block the keypress system-wise, but it is impossible, as far as I know, to identify the source of the keystroke (which keyboard it is from) and thus to selectively block them.
There is another project, here, that combines the two, but it is quite messy and heavy.
Is there a better way to achieve this? I am surprised that simple task is so complex.
If you are going to make the app windows only, you should look into Windows raw input api
It isn't that complicated.
I am writing a program to automate some work for me.
I have another program (OBS Studio) installed, which I use to capture video. OBS Studio is minimized to the system tray and listens to my configured hotkey CTRL + 1.
When I press CTRL + 1 anywhere, the software starts recording. It does not matter which application is in the foreground.
I am trying to do the same thing from my application, send a "global" hotkey. I have spend hours trying to achieve this, but without any result. SendKeys only works for the current open window (which does not exist), no results with PostMessage either and I tried the wrapper "InputSimulator"
So, to summarize:
Is it possible to send a hotkey/keystroke globally (for every application?)
If not, how would I send a hotkey to a program that is running in the background, without a window? I don't want to bring the app to the foreground.
Hopefully someone with a deeper understanding of these concepts can guide me...
I've found similar questions, but they remain unanswered:
Send global keystroke / fake a global hotkey from a Winforms application
Sources I studied (among others):
https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys(v=vs.110).aspx
https://dailyoverdose.wordpress.com/2009/10/28/postmessage-and-sendmessage/
https://ourcodeworld.com/articles/read/520/simulating-keypress-in-the-right-way-using-inputsimulator-with-csharp-in-winforms
Hi I'm trying to make a simple program that read keys from keyboard even if my application is running in the background.
Situation
I want make a timer to help me in a game. I already have the program with the timer, the problem is I can not start the timer without switching of the game window to my app window. So I configured the game keyboard to release the keys F11, F12. Now in game this keys do nothing.
Problem
I built a windows forms containing a listener for keydown event and a conditional for F11. But when I trigger another window (eg the game window) my application no longer hears the keyboard, cuz it's in the background.
Question
How can I build a app that hears the keyboard, even if it's not active window?
You need to install a global, low-level keyboard hook using the SetWindowHookEx API call. Using the WH_KEYBOARD_LL hook will set your application up to intercept keyboard events at all times, even when your application is not active.
This post on MSDN shows an example of how to achieve something close to what you want from C#.
I have an application to which I want to send the Ctrl-C keys combination. I am trying with SendMesssage, but I know that the application checks for Ctrl-C combination using GetKeyState and GetAsyncKeyState so SendMessage is pretty useless... How can I send the Ctrl-C combination to this window without calling SetForegroundWindow(hWnd)? I need a solution which works without focusing/bringing to front the window.
I am temporarily using this code (but requires focus):
SetForegroundWindow(hWnd);
SendKeys.SendWait("^(c)");
I am using C#, but C++ code is ok.
A long time ago, back when I was doing Sys Admin automation.. I used AutoIT. It's been a long time, but if you don't mind picking up their .dll...
This is the method I'd use.. it mentions you can send directly to a window/control without focus.. in some cases you can't..
AutoIT ControlSend Method
My app (in C#) need to interface with a USB bar-code scanner, which is basically working like a keyboard. It inputs the bar-code with an enter key at the end.
The app need to be work even when it's at background, so I am using low level keyboard hook to get and filter the bar-code out in the global key events. This part is already working.
Here is my problem: I don't want other apps to get the keyboard(scanner) inputs if it is a bar-code. And the normal key events should not be interfered. In one word, block the key events selectively. Is this possible?
My app is in C#, but I have no problem with C++ or more native solutions as long as it's easy to integrate in C#.
Thanks.
Additional Information:
The whole idea is working at background, even when it's not active. It watches the global key events stream and spot the bar-code sequence (already implemented with Hook). And most importantly, it do NOT interfere with normal keyboard events nor other applications' operation. That's why I cannot block all the key events or make it top-most.
I already can get the bar-code. I need to prevent other applications from getting the bar-code.
At the end of your keyboard hook you would call CallNextHookEx to execute next hook in the chain.
I would suggest that put some unique signature as a preamble for your barcode so that your keyboard hook procedure can detect it as a valid barcode input from your scanner. Now, when you get this data, just skip the call to 'CallNextHookEx' so that the chain will be discontinued and other programs won't get your barcode. Otherwise - call 'CallNextHookEx' so the chain can continue.
Note: This is my theory, I have never tried the exact same thing myself. I have however, written hooks in C++ and C#.
Check this project out
http://globalmousekeyhook.codeplex.com/
It is in C# as well so will make your coding easier. Sounds like all you need is to hook up the global key press event and suppress it by setting the Handled value or something similar.