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

  • Thread starter Thread starter Gary
  • Start date Start date
G

Gary

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
 
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

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
 
*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'"


: 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
:
:
 
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'"


: Hello,
:
: > MenuItem1_Click(MenuItem1, New System.EventArgs())
:
: Why not use 'MenuItem.PerformClick'?
:
: --
: Herfried K. Wagner
: MVP · VB Classic, VB.NET
: http://www.mvps.org/dotnet
:
:
 
Hello,

Tom Spink said:
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
 
Back
Top