473,387 Members | 1,517 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.

SendKeys Question..

Hi,

Was wondering if somebody could help.. I'm trying to use Sendkeys on a
Windows forms.

I have entered the following command to simulate a CTRL+ALT+1..

System.WindowsForms.SendKeys.Send("^%1");

This didn't work, so I then tried..

System.WindowsForms.SendKeys.Send("^%1");

This didn't work either, anybody got any ideas!!
Thanks

Wayne
Nov 15 '05 #1
5 8729
Wayne, this is going to simulate pressing those keys in successsion, not
holding ctrl and alt down while pressing 1. If that's what you are going
for try this: "^(%1)". The ()'s specify that % and 1 should be pressed
while holding ^.

--
Greg Ewing [MVP]
http://www.claritycon.com/

"Wayne Gibson" <wa**********@rendersoft.com> wrote in message
news:bj*******************@news.demon.co.uk...
Hi,

Was wondering if somebody could help.. I'm trying to use Sendkeys on a
Windows forms.

I have entered the following command to simulate a CTRL+ALT+1..

System.WindowsForms.SendKeys.Send("^%1");

This didn't work, so I then tried..

System.WindowsForms.SendKeys.Send("^%1");

This didn't work either, anybody got any ideas!!
Thanks

Wayne

Nov 15 '05 #2
Thanks, had tried that..

I think I forgot to mention, the reason for using this keyboard combination
is I have some software that providing a short cut key to do something for
me.. This doesn't appear to be picking it up...

I also tried Alt+Tab to switch applications and Ctrl+Esc to bring up the
start button, But neither of this too work... Any Ideas?

Thanks

Wayne
Nov 15 '05 #3

Hi Wayne,

I used an another software that can be invoke while pressing certain key to
simulate your function.
This software can hook system wide key stroke and whenever I press alt+F4,
the application will get
invoke, and the active window will not be closed.

I use sendkeys class to send "%{F4}" to my application, but the hook
application does not get invoked and
my form gets closed as usual.

I think the sendkeys class bypassed the message queue, so the hook can not
get notified.
In my .net application, the sendkeys class can succeed fire Alt+Tab and
letting the focus change, but it can not
fire ctrl+esc.(can not let the start menu pop up)

To work around your problem, I think you can use keybd_event() function
instead of sendkeys.(In win2000, it seems of that
it was replaced by sendinput() function).
May be you also can use sendmessage function to simulate certain hot key.

Also, how does your application get the hot key?
It used Keyboard hook?
I think the best way of simulating keyboard send keys event is using
WH_JOURNALPLAYBACK, please refer to MSDN.

If you still get some problem, do tell me, I am glad to work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Wayne Gibson" <wa**********@rendersoft.com>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: Re: SendKeys Question..
| Date: Thu, 4 Sep 2003 14:19:44 +0100
| Lines: 14
| Message-ID: <bj*******************@news.demon.co.uk>
| References: <bj*******************@news.demon.co.uk>
<ek**************@TK2MSFTNGP10.phx.gbl>
| NNTP-Posting-Host: 62.49.252.243
| X-Trace: news.demon.co.uk 1062681513 26355 62.49.252.243 (4 Sep 2003
13:18:33 GMT)
| X-Complaints-To: ab***@demon.net
| NNTP-Posting-Date: Thu, 4 Sep 2003 13:18:33 +0000 (UTC)
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| X-Priority: 3
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MSMail-Priority: Normal
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!kibo.news.demon.net!news.demon.co.uk!demon!no t-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:182254
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks, had tried that..
|
| I think I forgot to mention, the reason for using this keyboard
combination
| is I have some software that providing a short cut key to do something for
| me.. This doesn't appear to be picking it up...
|
| I also tried Alt+Tab to switch applications and Ctrl+Esc to bring up the
| start button, But neither of this too work... Any Ideas?
|
| Thanks
|
| Wayne
|
|
|

Nov 15 '05 #4

Hi Wayne,

Does your operating system win9x?
There is an already known issue that the win9x will ingnore the sendkeys
alt+tab.
For details, please refer to:
http://support.microsoft.com/default...microsoft.com:
80/support/kb/articles/Q129/8/39.asp&NoWebContent=1

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| X-Tomcat-ID: 161223555
| References: <bj*******************@news.demon.co.uk>
<ek**************@TK2MSFTNGP10.phx.gbl>
<bj*******************@news.demon.co.uk>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: v-*****@online.microsoft.com (Jeffrey Tan[MSFT])
| Organization: Microsoft
| Date: Fri, 05 Sep 2003 06:43:55 GMT
| Subject: Re: SendKeys Question..
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| Message-ID: <EX**************@cpmsftngxa06.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Lines: 72
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:182503
| NNTP-Posting-Host: TOMCATIMPORT2 10.201.218.182
|
|
| Hi Wayne,
|
| I used an another software that can be invoke while pressing certain key
to
| simulate your function.
| This software can hook system wide key stroke and whenever I press
alt+F4,
| the application will get
| invoke, and the active window will not be closed.
|
| I use sendkeys class to send "%{F4}" to my application, but the hook
| application does not get invoked and
| my form gets closed as usual.
|
| I think the sendkeys class bypassed the message queue, so the hook can
not
| get notified.
| In my .net application, the sendkeys class can succeed fire Alt+Tab and
| letting the focus change, but it can not
| fire ctrl+esc.(can not let the start menu pop up)
|
| To work around your problem, I think you can use keybd_event() function
| instead of sendkeys.(In win2000, it seems of that
| it was replaced by sendinput() function).
| May be you also can use sendmessage function to simulate certain hot key.
|
| Also, how does your application get the hot key?
| It used Keyboard hook?
| I think the best way of simulating keyboard send keys event is using
| WH_JOURNALPLAYBACK, please refer to MSDN.
|
| If you still get some problem, do tell me, I am glad to work with you.
|
| Best regards,
| Jeffrey Tan
| Microsoft Online Partner Support
| Get Secure! - www.microsoft.com/security
| This posting is provided "as is" with no warranties and confers no rights.
|
| --------------------
| | From: "Wayne Gibson" <wa**********@rendersoft.com>
| | Newsgroups: microsoft.public.dotnet.languages.csharp
| | Subject: Re: SendKeys Question..
| | Date: Thu, 4 Sep 2003 14:19:44 +0100
| | Lines: 14
| | Message-ID: <bj*******************@news.demon.co.uk>
| | References: <bj*******************@news.demon.co.uk>
| <ek**************@TK2MSFTNGP10.phx.gbl>
| | NNTP-Posting-Host: 62.49.252.243
| | X-Trace: news.demon.co.uk 1062681513 26355 62.49.252.243 (4 Sep 2003
| 13:18:33 GMT)
| | X-Complaints-To: ab***@demon.net
| | NNTP-Posting-Date: Thu, 4 Sep 2003 13:18:33 +0000 (UTC)
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| | X-Priority: 3
| | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| | X-MSMail-Priority: Normal
| | Path:
|
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
| e.de!kibo.news.demon.net!news.demon.co.uk!demon!no t-for-mail
| | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:182254
| | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| |
| | Thanks, had tried that..
| |
| | I think I forgot to mention, the reason for using this keyboard
| combination
| | is I have some software that providing a short cut key to do something
for
| | me.. This doesn't appear to be picking it up...
| |
| | I also tried Alt+Tab to switch applications and Ctrl+Esc to bring up the
| | start button, But neither of this too work... Any Ideas?
| |
| | Thanks
| |
| | Wayne
| |
| |
| |
|
|

Nov 15 '05 #5

Hi Wayne,

I have tried the keybd_event function, it does invoke my hotkey application.

Sample code listed below:
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk,byte bScan,int
dwFlags,int dwExtraInfo);

public const int VK_DELETE = 0x2E;
public const int VK_F4 = 0x73;
public const int VK_TAB = 0x9;
public const int VK_MENU = 0x12;
public const int KEYEVENTF_EXTENDEDKEY = 0x1;
public const int KEYEVENTF_KEYUP = 0x2;
public const int VK_CONTROL = 0x11;
public const int VK_ESCAPE =0x1B;

//send alt+tab

keybd_event(VK_MENU,0,0,0);
keybd_event(VK_TAB,0,0,0);
keybd_event(VK_TAB,KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0,KEYEVENTF_KEYUP,0);

//send control+esc

keybd_event(VK_CONTROL,0,0,0);
keybd_event(VK_ESCAPE,0,0,0);
keybd_event(VK_ESCAPE,KEYEVENTF_KEYUP,0);
keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,0);

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Wayne Gibson" <wa**********@rendersoft.com>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Subject: Re: SendKeys Question..
| Date: Thu, 4 Sep 2003 14:19:44 +0100
| Lines: 14
| Message-ID: <bj*******************@news.demon.co.uk>
| References: <bj*******************@news.demon.co.uk>
<ek**************@TK2MSFTNGP10.phx.gbl>
| NNTP-Posting-Host: 62.49.252.243
| X-Trace: news.demon.co.uk 1062681513 26355 62.49.252.243 (4 Sep 2003
13:18:33 GMT)
| X-Complaints-To: ab***@demon.net
| NNTP-Posting-Date: Thu, 4 Sep 2003 13:18:33 +0000 (UTC)
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| X-Priority: 3
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MSMail-Priority: Normal
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!kibo.news.demon.net!news.demon.co.uk!demon!no t-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:182254
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks, had tried that..
|
| I think I forgot to mention, the reason for using this keyboard
combination
| is I have some software that providing a short cut key to do something for
| me.. This doesn't appear to be picking it up...
|
| I also tried Alt+Tab to switch applications and Ctrl+Esc to bring up the
| start button, But neither of this too work... Any Ideas?
|
| Thanks
|
| Wayne
|
|
|

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Kanter | last post by:
Hello, I have a question regarding SendKeys(). I am working on a small VB .Net script that manipulates/automates programs through SendKeys(). Unfortunately, I have run into several problems. ...
2
by: RBohannon | last post by:
I need to create a report in MS Word populated with data from A2K. I have been asked to create the report in Word so that parts of it can be edited as necessary later. The data in the report are...
2
by: ABinBoston | last post by:
I have a macro that uses the SendKeys function to send F9 - to auto save a record. The Application runs perfectly on many PCs, but on one I get the following error. SendKeys Action Requires...
1
by: Bryan | last post by:
I am writing a C# Windows App that updates out Excel reports' modules. The app is complete, but has a problem. The only way MS allows you to unprotect the VBA code in Excel is to do it by hand or...
0
by: Austin | last post by:
Hello: I have written a very simple vb program (using the new .net interface). I have a website to which I must upload many files. The filenames are incremented in such a way that a simple...
4
by: atr2000 | last post by:
How can I perform a SendKeys.Send to the current active application from a windows service? Or is there a different way to do this? I currently receive the following error message: ...
0
by: neonspark | last post by:
I'm buidling some simple macro functionality for my app so the users can record a sequence of keyboard inputs and replay them reliably via some menu. Originally, I used: protected override bool...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have this code for sendKeys. This simply sends a text to the notepad. This method runs fine, but I don't see the notepad and the text entered in that notepad. Is there any way...
1
by: Boki | last post by:
Hi All, I am trying to create a auto login program. Below is the part of code, my issue is - the target form ( handle / window ) usually didn't perform the key I sent from my C# program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.