473,799 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(hwn d,WM_KEYDOWN,vk _control,code)
postmessage(hwn d,WM_KEYDOWN,"A ",code)
postmessage(hwn d,WM_KEYUP,"A", code)
postmessage(hwn d,WM_KEYUP,vk_c ontrol,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 8260
Example.

'The function is declared as a form class member.

Private Declare Function SendMessage Lib "user32.dll " Alias "SendMessag eA"
(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(hwn d,WM_KEYDOWN,vk _control,code)
postmessage(hwn d,WM_KEYDOWN,"A ",code)
postmessage(hwn d,WM_KEYUP,"A", code)
postmessage(hwn d,WM_KEYUP,vk_c ontrol,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**********@BT Internet.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 "PostMessag eA" _
(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 "SendMessag eA" _
(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 "PostMessag eA" _
(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 "SendMessag eA" _
(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
10227
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. I tried sending keys in VB with SendKeys, as well as using keybd_event API, but I'm not able to send any keys. It works very well for any local applications, but I can't pass the keys remotely. Is there any way to do it? Thanks! Etienne
4
9457
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 pass the socket to a class which just reads from the socket (in a thread). class Reader(Thread): def run(self): while 1:
1
5787
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
1321
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 unknown reason base.ProcessCmdKey calls method itself. How to fix ? Andrus.
0
2211
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 = true; } private void Form1_KeyDown(object sender, KeyEventArgs e) { label1.Text = e.Control.ToString() + "|" + e.Shift.ToString() + "|" + e.Alt.ToString() + "|" + e.KeyValue.ToString() + "|" +
3
9437
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()); char temp = { Convert.ToChar(Keys.Control), Convert.ToChar(Keys.X) };
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.