Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I don't know how to get the keypress event to determine if certain keys were pressed. I know about the KeyPreview property, and I know how to check if keys like the letter, number, or backspace keys were pressed, but I don't know how to do the delete key, arrow keys, and that kind of stuff. The ones that I need to use right now are the up and down arrow keys.
Take a look at my programs. Go to my web site.
Posted
I found out in MSDN that the KeyPress event doesn't see keys that don't have an output on the screen, such as the arrow keys, the Delete key, and the function keys. I need to use KeyDown or KeyUp instead for those. However, I found that when I use KeyDown, it only executes the code for the arrow keys if one of the text boxes on my form has the focus. It works fine in the KeyUp event, but then the focus moves if the arrow key is held down long enough, and I don't want it to do that.
Take a look at my programs. Go to my web site.
Posted
I've had some problems with KeyDown and KeyUp before... In some apps they just don't work, and in others they work fine. I haven't pinpointed the problem yet
Posted

This is some Code where i want to know if a function key is pressed and then do something.

 

...

if e.KeyData = Keys.Down or e.KeyData = Keys.F8 then

'do something

...

 

This Code can be found within the KeyUp-Event of my Form and is working.

 

Voca

Posted
This is some Code where i want to know if a function key is pressed and then do something.

 

...

if e.KeyData = Keys.Down or e.KeyData = Keys.F8 then

'do something

...

 

This Code can be found within the KeyUp-Event of my Form and is working.

 

Voca

 

I forgot, the KeyPreview Property of my form is set to true.

 

Voca

Posted

Actually, that doesn't help me with the problem that I have now. I can't get the arrow keys to work in the KeyDown event when a button has the focus. It only works when a text box has the focus. I am using:

 

If e.KeyCode = Keys.Up

I also tried e.KeyData and e.KeyValue, but they do the same thing. What is the difference between them anyway?

Take a look at my programs. Go to my web site.
Posted

I found out from another post how to do it.

 

Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
     If m.WParam.ToInt32 = Keys.Up Then
           'whatever the code is
     End If
End Function

Take a look at my programs. Go to my web site.
Posted
Oops. When I use the code on my last reply, the keys in my KeyPress event don't work for some reason. Well, actually, the fist time it should execute (unless an arrow key has been pressed), it works, but then it doesn't anymore.
Take a look at my programs. Go to my web site.
Posted

this is function that returns value ( bool )

 

try with this:

 

Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
     If m.WParam.ToInt32 = Keys.Up Then
           'whatever the code is
     End If
Return True
End Function

Some people are wise and some are other-wise.
Posted

Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
           If Asc(e.KeyChar) = CInt(System.Windows.Forms.Keys.Escape) Then
               Me.Close() ' Esc was pressed
           End If

           If Asc(e.KeyChar) = 112 Then 'p was pressed (toggles blnPause value)
               If blnPause = True Then
                   blnPause = False
                   Exit Sub
               Else
                   blnPause = True
               End If
           End If
       End Sub 'OnKeyPress

 

this works for me

mod2software

Home of the VB.NET Class Builder Utility - Demo and Full versions available now!

Posted (edited)

try with this

 

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean

''Implement your code here
'' If keyData = Keys.Escape Then .....

       MessageBox.Show(keyData.ToString)
  

Return True
End Function

Edited by sizer
Some people are wise and some are other-wise.
Posted
Getting closer... Now it works, but it blocks keyboard shortcuts to menu items. Also, I can't figure out the Keys.Whatever command for the "(," ")," and "^" keys.
Take a look at my programs. Go to my web site.
  • *Experts*
Posted

The easiest way to use the arrow keys is through the keyup event. This way you can also utilize the keydown and keypress events.

 

An example:

   Private Sub PIValue_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp

       If e.KeyCode = Keys.Right Or e.KeyCode = Keys.Up Then
           If tbarPI.value < 50 Then
               tbarPI.value += 1
           End If
       ElseIf e.KeyCode = Keys.Left Or e.KeyCode = Keys.Down Then
           If tbarPI.value >= 1 Then
               tbarPI.value -= 1
           End If
       End If
   End Sub

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
I want to use the KeyDown event, but the arrow keys don't work in it unless one of the text boxes has the focus. Maybe I should just just leave this feature out of my program. It's getting to be more trouble than it's worth. Why does something so simple have to be so complicated to do anyway?
Take a look at my programs. Go to my web site.
  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...