473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 8225
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Etienne Charland | last post by:
Hi, there is an application running on a remote desktop (under Citrix ICA, but the same problem applies for RDC or PC Anywhere). Now, I want to send keys to the remote application from a local app....
4
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I...
1
by: karunakar | last post by:
Hi all Just i want capture the with "Ctrl" (Key bord function) + any F1 or F4 In windows application How can capture the event in C# .net Regards, Venu
0
by: Andrus | last post by:
MDI WinForms 2 application. I need that Ctrl+F1 cycles through windows like Ctrl+Tab and Ctrl+Tab is redefined. I overrided MDI child form OnKeypress method but Ctrl+F1 press is ignored. For...
0
by: Yusuf Incekara | last post by:
I 've assigned a shortcut key for CTRL+SHIFT+1 key in my application. I can handle these keys in Form's keydown event. private void Form1_Load(object sender, EventArgs e) { this.KeyPreview =...
3
by: Blip | last post by:
Hello - I'm trying to wite these control characters to the serial port w/o success. I've tried sp.Write((Keys.ControlKey & Keys.X).ToString()); sp.Write((Keys.Control & Keys.X).ToString()); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.