Home > Net >  Form the Form get the user key, and get the goods handle problems, application exactly how to write?
Form the Form get the user key, and get the goods handle problems, application exactly how to write?

Time:10-28

I am using VS2019, WIN10 64 - bit system, I see some posts, saying is:

///////two symbols middle copy from the Internet//////////
To be introduced at the beginning the namespace
Using System. The Runtime. InteropServices;

Gets the current window handle: GetForegroundWindow ()

[DllImport (" user32. DLL, "CharSet=CharSet. Auto, ExactSpelling=true)]
Public static extern IntPtr GetForegroundWindow ();

The return value type is IntPtr that for the current gains focus window handle

Method of use: IntPtr myPtr=GetForegroundWindow ();
/////////////////

According to the above methods, the I found an error, as shown in figure

What is how to write?
I wrote is today with the wizard button a window procedure, operation form in the game window screen, see the F7 key, automatically get the game window handle, automatic button and then the background, and in the evening want to use c # to achieve this function, retrieve the user key, found that the c # how to realize and get the window handle, and then to the background behind the key, also want to, give advice or comments

CodePudding user response:

To encapsulate a hook to catch shortcut keys, and then with a c + + Sendmessage, keystroke messages sent,
  •  Tags:  
  • C#
  • Related