PC Review


Reply
Thread Tools Rate Thread

Capture Function Key press event

 
 
MS Newsgroups
Guest
Posts: n/a
 
      2nd Sep 2003
Hi,

I would like to capture when a user presses F5 in my Windows form
application, but the keypress event does not seem to fire when a function
key is pressed, Is there another way of doing this ?

This code works fine for all keys except function keys

Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)
Dim myKey As Char
myKey = e.KeyChar
MsgBox(myKey.ToString)
End Sub


Regards

Niclas


 
Reply With Quote
 
 
 
 
Gary
Guest
Posts: n/a
 
      2nd Sep 2003
Niclas,

Set the form's "KeyPreview" prop. to False and try the following code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

If e.KeyCode = Keys.F5 Then

MessageBox.Show("F5 pressed")

End If

End Sub

Let me know if this works.

- Gary -


"MS Newsgroups" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi,
>
> I would like to capture when a user presses F5 in my Windows form
> application, but the keypress event does not seem to fire when a function
> key is pressed, Is there another way of doing this ?
>
> This code works fine for all keys except function keys
>
> Protected Overrides Sub OnKeyPress(ByVal e As
> System.Windows.Forms.KeyPressEventArgs)
> Dim myKey As Char
> myKey = e.KeyChar
> MsgBox(myKey.ToString)
> End Sub
>
>
> Regards
>
> Niclas
>
>



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      2nd Sep 2003
"MS Newsgroups" <(E-Mail Removed)> schrieb
> I would like to capture when a user presses F5 in my Windows form
> application, but the keypress event does not seem to fire when a
> function key is pressed, Is there another way of doing this ?


Use the KeyDown event. Keypress only fires for keys that create chars.


--
Armin

 
Reply With Quote
 
Prateek
Guest
Posts: n/a
 
      2nd Sep 2003
Hi Niclas,

KeyPress event will not fire for function keys as this event only traps
printable keys. You will need to use the KeyUp or KeyDown events in this
case.

-Prateek

"MS Newsgroups" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
Hi,

I would like to capture when a user presses F5 in my Windows form
application, but the keypress event does not seem to fire when a function
key is pressed, Is there another way of doing this ?

This code works fine for all keys except function keys

Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)
Dim myKey As Char
myKey = e.KeyChar
MsgBox(myKey.ToString)
End Sub


Regards

Niclas



 
Reply With Quote
 
MS Newsgroups
Guest
Posts: n/a
 
      2nd Sep 2003
Cheers Armin. thats the way to do it.

Thanks

Niclas
"Gary" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Niclas,
>
> Set the form's "KeyPreview" prop. to False and try the following code:
> Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
>
> If e.KeyCode = Keys.F5 Then
>
> MessageBox.Show("F5 pressed")
>
> End If
>
> End Sub
>
> Let me know if this works.
>
> - Gary -
>
>
> "MS Newsgroups" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi,
> >
> > I would like to capture when a user presses F5 in my Windows form
> > application, but the keypress event does not seem to fire when a

function
> > key is pressed, Is there another way of doing this ?
> >
> > This code works fine for all keys except function keys
> >
> > Protected Overrides Sub OnKeyPress(ByVal e As
> > System.Windows.Forms.KeyPressEventArgs)
> > Dim myKey As Char
> > myKey = e.KeyChar
> > MsgBox(myKey.ToString)
> > End Sub
> >
> >
> > Regards
> >
> > Niclas
> >
> >

>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      2nd Sep 2003
Hello,

"MS Newsgroups" <(E-Mail Removed)> schrieb:
> I would like to capture when a user presses F5 in my Windows
> form application, but the keypress event does not seem to fire
> when a function key is pressed, Is there another way of doing this ?


Set the form's 'KeyPreview' property to 'True' and add this code:

\\\
Private Sub Form1_KeyDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs _
) Handles MyBase.KeyDown
If e.KeyCode = Keys.F5 Then
MsgBox("F5 pressed!")
End If
End Sub
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to capture the event that someone press a 'del' key when highlight a row in a datagrid? ywchan Microsoft C# .NET 1 16th Jul 2005 07:04 AM
Capture Key Press Bob Achgill Microsoft VB .NET 7 11th May 2004 08:44 PM
Capture all Key Press events Chris Auld Microsoft Dot NET Compact Framework 3 6th Nov 2003 03:00 PM
Capture Action Button Press David Hanson Microsoft Dot NET Compact Framework 2 31st Oct 2003 10:30 PM
capture press power off from device Alf Microsoft Dot NET Compact Framework 1 17th Oct 2003 11:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:57 PM.