send ctrl keys to another application

  • Thread starter Thread starter Str Noetika
  • Start date Start date
S

Str Noetika

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.
 
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 said:
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.

Best Regards - OHMBest Regards - OHM (e-mail address removed)
 
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 !
 
* Str Noetika said:
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'.
 
Back
Top