By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

SendKeys Question..

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a

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

P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.