469,603 Members | 2,144 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

send ctrl keys to another application

Hi,

How can I send ctrl keys (like ctrl A, ctrl C) from a VB application to
another existing application (like word, excel...) ? I tried to send
postmessages like
postmessage(hwnd,WM_KEYDOWN,vk_control,code)
postmessage(hwnd,WM_KEYDOWN,"A",code)
postmessage(hwnd,WM_KEYUP,"A",code)
postmessage(hwnd,WM_KEYUP,vk_control,code)

I tried several codes according to documentation like 0 and xC..., the
target windows does receive the codes (checked with spy++) but doesn't
execute the ctrl key command. Did I do something wrong ? is there
another way ?

Thanks so much for whom may help me.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
3 7768
Example.

'The function is declared as a form class member.

Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal
lParam As Int32) As Int32

Const WM_VSCROLL As Int32 = &H115

Const SB_LINEDOWN As Int32 = 1

Const SB_LINEUP As Int32 = 0

Regards - OHM

Str Noetika wrote:
Hi,

How can I send ctrl keys (like ctrl A, ctrl C) from a VB application
to another existing application (like word, excel...) ? I tried to
send postmessages like
postmessage(hwnd,WM_KEYDOWN,vk_control,code)
postmessage(hwnd,WM_KEYDOWN,"A",code)
postmessage(hwnd,WM_KEYUP,"A",code)
postmessage(hwnd,WM_KEYUP,vk_control,code)

I tried several codes according to documentation like 0 and xC..., the
target windows does receive the codes (checked with spy++) but doesn't
execute the ctrl key command. Did I do something wrong ? is there
another way ?

Thanks so much for whom may help me.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Best Regards - OHMBest Regards - OHM On**********@BTInternet.Com
Nov 20 '05 #2
Thanks,

It doesn't work more, I used sendmessage and after postmessage as I saw
in spy++ that keyboards events came with post.

My functions declarations are as follow :

Public Declare Function PostMessage Lib "User32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long

Public Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long

What I just can't understand is that the result is exactly the same from
my soft and from the keyboard, checked with spy++ when I send
vk_control/vk_insert/vk_insert/vk_control to simulate a copy command.

What is more strange, is that when I replace vk_insert with "C", I get
the four actions + the c character, which looks like the targeted
windows didn't interpretate the keystroke as I thought.

thanks for all advices !
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3
* Str Noetika <de***********@noetika.com> scripsit:
It doesn't work more, I used sendmessage and after postmessage as I saw
in spy++ that keyboards events came with post.

My functions declarations are as follow :

Public Declare Function PostMessage Lib "User32" Alias "PostMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long

Public Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long


Your declares are wrong for VB.NET. Replace all 'As Long' with 'As
Int32', 'hwnd' can be declared as 'IntPtr'. Remove the 'Alias...' and
declare the function as 'Auto'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Etienne Charland | last post: by
4 posts views Thread by jas | last post: by
reply views Thread by Andrus | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.