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

SendKeys.Send("^(P)") not working

P: n/a
Hi,

I am trying to use the "System.Windows.Forms.SendKeys" class for triggering
the Ctrl+P key.

Syntax:
System.Windows.Forms.SendKeys.Send("^(P)")

This is not working ..what could be the reason..?

Situation:
I have a menu in my form, which is given a short key "Ctrl+P", now when the
form gets loaded, when I press the "Ctrl+P" then the menu functionality is
working. But the same thing I wanted to trigger on a button on click with
the following code..

System.Windows.Forms.SendKeys.Send("^(P)")

this is not working..

Note: Infact any of the "Ctr+AnyAlphabet", ie, Ctrl+A or..Ctrl+B..or
...C..like that is not working when using
System.Windows.Forms.SendKeys.Send("^(P)")
But the same thing is working fine, when I have as "Ctrl+AnyNumber", ie,
Ctrl+1 or Ctrl+2 with
System.Windows.Forms.SendKeys.Send("^(1)")

Please help!
- Gary
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Gary,

Try System.Windows.Forms.SendKeys.Send("^(p)")

The shortcut key is Ctrl+P and this menu item is triggered by pressing Ctrl
+ "small p" and not Ctrl + "capital P". Using SendKeys, you are sending Ctrl
+ "capital P", which very rightly, will not and does not work.

-Prateek

"Gary" <ms****@microsoft.com> wrote in message
news:e1**************@TK2MSFTNGP12.phx.gbl...
Hi,

I am trying to use the "System.Windows.Forms.SendKeys" class for triggering
the Ctrl+P key.

Syntax:
System.Windows.Forms.SendKeys.Send("^(P)")

This is not working ..what could be the reason..?

Situation:
I have a menu in my form, which is given a short key "Ctrl+P", now when the
form gets loaded, when I press the "Ctrl+P" then the menu functionality is
working. But the same thing I wanted to trigger on a button on click with
the following code..

System.Windows.Forms.SendKeys.Send("^(P)")

this is not working..

Note: Infact any of the "Ctr+AnyAlphabet", ie, Ctrl+A or..Ctrl+B..or
...C..like that is not working when using
System.Windows.Forms.SendKeys.Send("^(P)")
But the same thing is working fine, when I have as "Ctrl+AnyNumber", ie,
Ctrl+1 or Ctrl+2 with
System.Windows.Forms.SendKeys.Send("^(1)")

Please help!
- Gary

Nov 20 '05 #2

P: n/a
Thanks a lot Prateek,
It certainly works :)

- Gary -

"Prateek" <pr**********@msn.com> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
Hi Gary,

Try System.Windows.Forms.SendKeys.Send("^(p)")

The shortcut key is Ctrl+P and this menu item is triggered by pressing Ctrl + "small p" and not Ctrl + "capital P". Using SendKeys, you are sending Ctrl + "capital P", which very rightly, will not and does not work.

-Prateek

"Gary" <ms****@microsoft.com> wrote in message
news:e1**************@TK2MSFTNGP12.phx.gbl...
Hi,

I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key.

Syntax:
System.Windows.Forms.SendKeys.Send("^(P)")

This is not working ..what could be the reason..?

Situation:
I have a menu in my form, which is given a short key "Ctrl+P", now when the form gets loaded, when I press the "Ctrl+P" then the menu functionality is
working. But the same thing I wanted to trigger on a button on click with
the following code..

System.Windows.Forms.SendKeys.Send("^(P)")

this is not working..

Note: Infact any of the "Ctr+AnyAlphabet", ie, Ctrl+A or..Ctrl+B..or
..C..like that is not working when using
System.Windows.Forms.SendKeys.Send("^(P)")
But the same thing is working fine, when I have as "Ctrl+AnyNumber", ie,
Ctrl+1 or Ctrl+2 with
System.Windows.Forms.SendKeys.Send("^(1)")

Please help!
- Gary

Nov 20 '05 #3

P: n/a
*YIKES* Don't Do This!!!! You shouldn't send keystrokes around, just to
invoke some code, you can do it directly. Sending keystrokes is *very*
unreliable, and usually bad programming practice.

<Rant Over>

Hi, Just call the event handler that responds to the menu item:

Public Sub MenuItem1_Click(...) Handles MenuItem1.Click
' This is the sub that handles your menu item click
End Sub

Public Sub ButtonClick (...) Handles Button1.Click
' This is your button

MenuItem1_Click(MenuItem1, New System.EventArgs())

End Sub

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Gary" <ms****@microsoft.com> wrote in message
news:e1**************@TK2MSFTNGP12.phx.gbl...
: Hi,
:
: I am trying to use the "System.Windows.Forms.SendKeys" class for
triggering
: the Ctrl+P key.
:
: Syntax:
: System.Windows.Forms.SendKeys.Send("^(P)")
:
: This is not working ..what could be the reason..?
:
: Situation:
: I have a menu in my form, which is given a short key "Ctrl+P", now when
the
: form gets loaded, when I press the "Ctrl+P" then the menu functionality is
: working. But the same thing I wanted to trigger on a button on click with
: the following code..
:
: System.Windows.Forms.SendKeys.Send("^(P)")
:
: this is not working..
:
: Note: Infact any of the "Ctr+AnyAlphabet", ie, Ctrl+A or..Ctrl+B..or
: ..C..like that is not working when using
: System.Windows.Forms.SendKeys.Send("^(P)")
: But the same thing is working fine, when I have as "Ctrl+AnyNumber", ie,
: Ctrl+1 or Ctrl+2 with
: System.Windows.Forms.SendKeys.Send("^(1)")
:
: Please help!
: - Gary
:
:
Nov 20 '05 #4

P: n/a
Hello,

"Tom Spink" <th**********@ntlworld.com> schrieb:
MenuItem1_Click(MenuItem1, New System.EventArgs())


Why not use 'MenuItem.PerformClick'?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #5

P: n/a
That's the one. I wasn't sure if it was a member, I knew about a button, but
not a menu item. I couldn't check, because VS.NET was in VC++ mode. ;-)

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:uA**************@tk2msftngp13.phx.gbl...
: Hello,
:
: "Tom Spink" <th**********@ntlworld.com> schrieb:
: > MenuItem1_Click(MenuItem1, New System.EventArgs())
:
: Why not use 'MenuItem.PerformClick'?
:
: --
: Herfried K. Wagner
: MVP · VB Classic, VB.NET
: http://www.mvps.org/dotnet
:
:
Nov 20 '05 #6

P: n/a
Hello,

"Tom Spink" <th**********@ntlworld.com> schrieb:
That's the one. I wasn't sure if it was a member, I knew
about a button, but not a menu item.


I was not sure too but then I thought the framework would be very
inconsistent if there was not a 'PerformClick' method for the 'MenuItem'
class too.

;-)

I couldn't check, because VS.NET was in VC++ mode. ;-)

LOL

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.