Home > Back-end >  For help, to other applications of the insertion point output clipboard words how to achieve?
For help, to other applications of the insertion point output clipboard words how to achieve?

Time:09-27

I want to make a program, press the global hotkeys, put the contents of the clipboard and paste it to other programs (such as notepad) cursor,
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 window

CodePudding 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
reference 7 floor ccrun 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,


Writing in the process of global hotkeys, still doesn't work, Windows 7/bcb6, very strange,
Void __fastcall TMainBox: : OnWMSysCommand (TMessage & amp; Message)
{
If (Message. The WParam==0 x1001) {
The HWND HWND;
HWnd=GetForegroundWindow ();//get the current window
: : PostMessage (hWnd WM_PASTE, 0, 0);//WM_CLOSE SendMessage

}
}

I tried some postmessage, sendmessage are incorrect,

Finally, simulation button test succeeded,

Void __fastcall TMainBox: : OnWMSysCommand (TMessage & amp; Message)
{

If (Message. The WParam==0 x1001) {

The Clipboard () - & gt; AsText="My text.";

//send a Ctrl + V
Keybd_event (17, MapVirtualKey (17, 0), 0, 0).//press Ctrl key
Keybd_event (86, MapVirtualKey (86, 0), 0, 0).
Keybd_event (86, MapVirtualKey (86, 0), KEYEVENTF_KEYUP, 0).
Keybd_event (17, MapVirtualKey (17, 0), KEYEVENTF_KEYUP, 0).//release the Ctrl key

}

}
  • Related