4

I'm working on a project that needs to emulate a keypress of the Windows key. I've tried SendKeys.Send to no avail.

Specifically, the windows key needs to come in concert with a button. That is, I want to send Windows Key and plus / minus.

0

4 Answers 4

7

I would add that it is often unlikely for you to find lower level functions like these in the .NET framework. If you were confused as to why the suggestions both pointed to "non C#" functions, then you probably could use some details on P/Invoke.

Basically there are ways to define C# functions that "tie" them to Windows API functions that do not exist within .NET assemblies (Instead they are typically implemented in C++ and available as a standard DLL). This process is considered to be "(Windows) Platform Invoking" (thus P/Invoke).

It can be a bit wobbly at first to match up all the data types between C++ and C# style calls, but fortunately, there are others out there that have paved the way.

The suggested function, SendInput, has a PInvoke wrapper over at PInvoke.net. This wrapper class, when available in your assembly, will allow you to call SendInput as if it were a C# function.

PInvoke.net is basically a PInvoke wiki for well known API calls in windows, and typically has a C#/VB.NET wrapper of API calls.

2

I think your best bet is using keybd_event keydown (called ExtendedKey) with the LWin value of the System.Windows.Forms.Keys enum, then keydown second character (+), and keyup both keys.

I do not believe SendKeys works with the Windows key as a modifier.

1

This may be overkill, but you could try using AutoItX which is a way to use AutoIt as a DLL. I've only written standalone scripts, but I know AutoIt makes it very easy to simulate pressing the Windows key.

For example, to open the run dialog is just:

Send("#r") ;Win + R = run

1

Try SendInput or the older keybd_event

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.