Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
1.this is winfrom project
2.I register a hotkey(use windows api)
3.override WndProc() method, code is below.
result:when i select text in txt,<Clipboard.ContainsText()>expression is true,others also,but when current program is chrome browser,it's is false.

C#
protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        case 0x0312:    //RegisterHotKey handle
            if (m.WParam.ToString().Equals("225"))
            {
                //clear data
                Clipboard.Clear();
                SendKeys.SendWait("^c");
                SendKeys.Flush();
                if (Clipboard.ContainsText())//Only when the Chrome browser, the expression is false
                {
                    MessageBox.Show("get text");
                }
            }
            break;
    }
    base.WndProc(ref m);
}
Posted
Updated 17-Dec-14 0:16am
v3
Comments
Praveen Kumar Upadhyay 17-Dec-14 4:56am    
Please mention your question too. Your question is not clear.

It's entirely possible that you didn't read what the MSDN data said: http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.sendwait(v=vs.110).aspx[^]

"The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds. The SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWait method will not wait for messages to be processed when they are sent to another process."

So it is entirely possible that you need to consider timing issues when you do this: perhaps testing with a Thread.Sleep(5000) before the Clipboard check would help?
 
Share this answer
 
Comments
mine_to_code 17-Dec-14 8:43am    
first, i have read msdn.second, thread.sleep() isn't work.
remove line
C#
Clipboard.Clear();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900