About Chris Expertise I can answer pretty much any question relating to VB.NET and its use in a Windows environment. I specialize in ASP.NET web development and MSSQL database access.
Experience I have over 5 years of industry experience using VB.NET and other .NET technologies for web and database development.
Education/Credentials I have some college education, but does it really matter in this field of work?
Expert: Chris Date: 8/11/2007 Subject: Accessing other programs selected text
Question hello Chris.
I want to write a dictionary sofware.
It should be lunched when the user select a text in any other programs and then press an especial key (For example Alt F10) . Such as Babylon Dictionary.
So I have 2 problems.
1- Lunching my dictionary by pressing an especial key.
2 - Accessing selected text in other program.
Can you help me ?
Thanks alot.
This example program, through a module called WndUtils in the SendKeys.vb file, demonstrates how to simulate a keypress in another program. You'll want to simulate the Control+C key combination, and send it to the active window.
Module CopyActiveWindow
Const KEYEVENTF_KEYUP As UInt32 = 2
Const VK_CONTROL As Byte = &H11 ' 0x11h
Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" ( _
ByVal hWnd As IntPtr) As Boolean
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As IntPtr
Declare Sub SendKeyboardEvent Lib "user32" Alias "keybd_event" ( _
ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInt32, ByVal dwExtraInfo As UInt32)
Public Sub SendCtrlC(ByVal hWnd As IntPtr)
SetForegroundWindow(hWnd)
SendKeyboardEvent(VK_CONTROL, 0, 0, 0)
SendKeyboardEvent(&H43, 0, 0, 0) ' Send the C key (0x43h is "C")
SendKeyboardEvent(&H43, 0, KEYEVENTF_KEYUP, 0)
SendKeyboardEvent(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0) ' Left Control Up
End Sub
End Module
Calling SendCtrlC(GetForegroundWindow()) from inside an event handler from the hotkey utility I referenced should do as you want, although I'm having trouble getting the Ctrl+C to go through properly myself.
I hope this helps - let me know if you can get it to work.