C# - Detecting Keydown and KeyUp events in the background - c#

I’ve been trying to create an console application which runs in the background detecting any key ups and keydown events, I’ve seen some threads on global key hooks however, I’m unable to make it detect key ups and key downs rather then key presses.
I’d like some advice on how to go about it, any help is valued and appreciated, thank you.

Figured out a solution using GetAsyncKeyState()

Related

Is there a way to get rid of the short pause in reaction after you press a key for the first time and hold it down?

I'm trying to make a game in WPF, C# where it would be crucial to have quick movements with the keyboard. Does anyone know how to get rid of the said phenomena?
What you are likely seeing in terms of a 'delay' is the keyboard repeat delay, which is controlled by the operation system (see Control Panel -> Keyboard).
You will probably have better luck working with the KeyDown and KeyUp attached events. https://msdn.microsoft.com/en-us/library/system.windows.input.keyboard.keydown(v=vs.110).aspx
By handing these events, you can handle repeating the functionality as frequently as you want until the KeyUp event is received.

MonoDevelop - Detect Enter Keypress in TextBox

I am currently making a web browser in MonoDevelop using C#, but I am having problems implementing the Keypress event.
I already know the code for how to make the web browser navigate, but the problem is that the keypress event for the enter key won't fire in the textbox.
I have tried other alphabetic keys (like Gdk.Key.a), and they work properly, but the enter key does not work.
I have also tried add [GLib.ConnectBefore] attribute before the keypress event, but it still doesn't make a difference.
Can someone please give me the whole code, if you don't mind? Because there are three different types of Enter keys in the Gdk.Key function, and I don't know which one to use.
I am using MonoDevelop 2.6
Thanks for your help
I have figured out how to solve this problem.
I was using the wrong event.
You do NOT use the OnKeyPress or OnKeyRelease events to get the signal of the Enter key. You would need to use the Control.Activated event.
The Activated event fires only when the return (enter) key is pressed.
I hope it's the same for every one!
Thanks for trying to help!

Is it possible to block keyboard input selectively in Windows? How?

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.

Creating/posting input events in C#

Is it possible to programmatically create input events in c#.
I want to be able to simulate any input, such as pressing a button on the keyboard or moving the mouse pointer from my application. The events generated by the application need to behave (preferably) in exactly the same way that an actual key press for instance does (post an event to the system event queue that is given for applications to process).
I seem to be unable to find any documentation about doing this from c# code after googling for an hour.
As always, any answers will be greatly appreciated.
You can try SendKeys for keyboard input. For more control, and mouse events too, you should P/invoke SendInput().
Be warned that this is difficult to get right and you may find alternative approaches more amenable.

keyboard press without Hardware press

how can I press "Enter" on c# and WPF without pressing enter on hardware keyboard ?
Ah, so you're saying SendKeys is unavailable?
Check these threads, on the MSDN forums: http://social.expression.microsoft.com/Forums/en-US/wpf/thread/915cb53a-704b-4047-8fd0-e7c5a8feae5e/
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/6557c1eb-6eb5-4f4a-84d6-4ae4fb5b9dab/
Sounds like you can trap KeyDown events, but that's not exactly what you want...
Oh, wait! Check this SO thread: How can I programmatically generate keypress events in C#?
Beyond that, How and why do you need to send "Enter" without a keyboard press? There may be a different solution lurking there. :)
Assuming that you're working with WindowsForms... by using SendKeys.Send("{ENTER}");
See this documentation here as well: http://msdn.microsoft.com/de-de/library/system.windows.forms.sendkeys.send.aspx

Categories

Resources