How to simulate pressing Fn+F6? - c#

Method SendKeys.Send does not allow the press Fn key, which exists on laptop's keyboards. How can I simulate pressing this key from C#?

You can't, and you don't need to. The Fn key only exists as a key as far as the keyboard circuit is concerned.
When the key code is sent to the operating system, it looks just as if the function keys were regular keys as on a regular keyboard. The operating system doesn't even know that the Fn key exists, that is taken care of by the special keyboard circuit in the laptop.
To make a function key press on a laptop, just send the regular key code for a function key as on a regular keyboard.
If there are any other key combinations where the Fn key is used, they either have their own key codes, or they are simply not possible to send because they are handled by the laptop, not by the operating system.

I have never tried it, but I think you can do it with another way. Create a keydown event on a textbox and press fn key at runtime and then check what code or what keyValue it returns. Then use that value in your SendKeys.Send method.

Related

Detecting key in C# console, without "using" it

I am trying to make a simple menu.
My question is simple: Is there a way to detect if key is pressed directly from the keyboard? In such way, that even if the user has started typing something, if he presses "~" it would be detected and some action will follow?
I know that is not possible in the console. I could only use Console.ReadKey() but that accepts the whole character, and if its not '`' it is discarded. Possible fix could be to add that key to the string later, but that would require the first key to be "~" which is annoying.
That is why I need something to detect the keys as they are pressed. I hope you can help.
Thanks.

How to simulate pressing a custom keyboard key

I have an extended keyboard and I want to simulate the key press of a special key that switches the keyboard mode. For that I think I need to find out key code, but can't figure out how can I get it. It's an extra key on my keyboard, not part of the ConsoleKey enum, and the only functions I've found to catch keys work with this enum.
If the key does something like change the keyboard color, this will depend on whether or not there is software on the computer which can do so as well. If not, this is probably just a local switch to the keyboard and that key isn't on the keymap for the keyboard itself, ether.
If it changes something else, it will depend on if there is driver software for the device or if it uses a default Windows driver.
If it takes installed software, it's probably a custom event (like some joysticks have) and would only be found if you use a reference to a library distributed by the keyboard manufacturer.
If it does not, then the switching mode is probably a "remap" mode tied to the keyboard firmware, and just changes which KeyDown event the affected keys send. If this is true, there is no way for Windows to even see what setting the keyboard is on.
I would say the logic for the function key changes is on the keyboard itself. For instance, the Fn key on my laptop does not cast any keyboard events by itself, but when combined with certain other keys, a key code is sent to the OS with a key code that triggers certain functionality.
For instance, in my keyboard Fn + Left lowers the volume, but the virtual key sent to the OS is VK_VOLUME_DOWN (see this for a list of virtual keys.)
Good news is, you can test the keys individually to see which key codes get sent to the OS! To accomplish this, you might want to set up a low-level keyboard hook) using P/Invokes.
There's a tutorial on CodeProject that may be useful to you.

TAPI, C#: Detecting key presses on a phones keypad

I'm attempting to set up a system where I phone a number, and then to confirm it isn't an answering machine I want the recipient to press a phone key to forward the call. The trouble is I'm struggling to find the event that gets raised for phone key presses.
I imagine it is a tone event but nothing seems to be raising.
I could also do with knowing how to detect what key is pressed as well.
Thanks,
Ryan
These are called DTMF tones, TAPI can detect and report them via the ITDigitDetectionEvent interface.
You need to setup the appropriate event filter and tell ITLegacyCallMediaControl::DetectDigits that you are looking for DTMF.

Detect/Block SendKeys.Send key messages

I was wondering if there was a way to detect if key strokes are from the keyboard or a SendKeys.Send call.
I would like to block specific SendKeys.Send keys but if those keys are directly from the keyboard then let them go.
Create a console application and run the code located here: http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx
Create a second application that will fire SendKeys.Send when you click a button. You will notice that the first console application detects key strokes from the keyboard but not keys from SendKeys.Send
I'm sure you could you use the code from the article to detect if the keystroke came from the keyboard or SendKeys.Send

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.

Categories

Resources