Only the last step, do not to come out, ask everybody to help, ideas are as follows:
Step 1, registered global hotkeys:
Void __fastcall TMainBox: : FormCreate (TObject * Sender)
{
RegisterHotKey (Handle, 0 x1001, MOD_CONTROL, 0 x31);//Ctrl + 1
}
Step 2, monitoring whether the hotkey press:
Void __fastcall TMainBox: : OnWMSysCommand (TMessage & amp; Message)
{
If (Message. The WParam==0 x1001) N1Click (Application);//if you press Ctrl + 1, perform N1Click process,
}
Step 3, hotkey response process,
//# include & lt; Clipbrd. Hpp>//contains the clipboard header file
Void __fastcall TMainBox: : N1Click (TObject * Sender)
{
The Clipboard () - & gt; AsText="111";//to put the system clipboard contents as text "111"
/*
At this time, open the notepad, press Ctrl + 1, in the clipboard into 111,
Press Ctrl + v to post the text notepad cursor,
How to don't have to press Ctrl + v, clipboard text output directly to the cursor? Please help, thank you,
//the code below send Ctrl + v simulation, test is not successful,
The HWND HWND;
HWnd=GetForegroundWindow ();//get the current window handle
Keybd_event (VK_CONTROL, 0, 0, 0).
PostMessage (hWnd, WM_KEYDOWN, x76 0, 0).
PostMessage (hWnd, WM_KEYUP, x76 0, 0).
Keybd_event (KEYEVENTF_KEYUP VK_CONTROL, 0, 0);
*/
}
CodePudding user response:
WM_PASTE messages sent to the target windowCodePudding user response:
Thank you old demon, can a specific point,CodePudding user response:
Dizzy, more specific, you are not handle to get yao:HWnd=GetForegroundWindow ();
: : SendMessage (hWnd WM_PASTE, 0, 0);
CodePudding user response:
Tried it on, no,The Clipboard () - & gt; AsText="111";
The HWND HWND;
HWnd=GetForegroundWindow ();//get the current window
PostMessage (hWnd WM_PASTE, 0, 0);
CodePudding user response:
Thanks, old demon, and people don't appreciate,CodePudding user response:
Not tried,, strange,The Clipboard () - & gt; AsText="111";
The HWND HWND;
HWnd=GetForegroundWindow ();//get the current window
SendMessage (hWnd WM_PASTE, 0, 0);//WM_CLOSE
WM_PASTE invalid and WM_CLOSE effective exit notepad, please again give directions,
CodePudding user response:
You call this code in any event? If it is a button click event, when you click on the button, GetForegroundWindow the returned handle, the window is not what you expected, you use GetClassName obtain the hWnd of the name of the class, then the output, is it you want to see,CodePudding user response:
The