How to send keyboard scan codes manually?

I am working on a project that should emulate a keystroke of Windows. I tried SendKeys.Send to no avail.

In particular, the Windows key should be combined with the button. That is, I want to send Windows Key and plus / minus.

+4
source share
4 answers

This may be redundant, but you can try using AutoItX , which is a way to use AutoIt as a DLL. I just wrote stand-alone scripts, but I know that AutoIt imitates Windows keystrokes very easily.

For example, to open the startup dialog, simply:

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

+1
source

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 sentences pointed to non-C # functions, you could probably use some details in P / Invoke .

Basically, there are ways to define C # functions that "bind" them to Windows API functions that are not in .NET assemblies (instead, they are usually implemented in C ++ and are available as a standard DLL). This process is considered the "(Windows) Invocation" (thus P / Invoke).

At first, it might be a little shaky that all data types match between C ++ and C # style calls, but, fortunately, there are others that paved the way.

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

PInvoke.net is basically the PInvoke wiki for well-known API calls on Windows and usually has a C # / VB.NET API wrapper.

+6
source

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

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

+2
source

Try SendInput or older keybd_event

0
source

All Articles