473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Help - KeyUp doesn't seem to be responding

Please take a look at my code....

Expand|Select|Wrap|Line Numbers
  1.     Const WM_KEYDOWN As Integer = &H100
  2.     Const WM_SYSKEYDOWN As Integer = &H104
  3.     Const WM_KEYUP As Integer = &H101
  4.     Const WM_SYSKEYUP As Integer = &H105
  5.  
  6.  
  7.     Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
  8.  
  9.  
  10.  
  11.         Dim XLocation As Integer = PictureBox2.Location.X
  12.         Dim Ylocation As Integer = PictureBox2.Location.Y
  13.  
  14.         If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
  15.  
  16.             Select Case (keyData)
  17.                 Case Keys.W
  18.                     Me.Timer2.Start()
  19.  
  20.                     Me.PictureBox2.SetBounds(XLocation, Ylocation - Me.ComboBox1.Text, 100, 100)
  21.                     If Me.PictureBox2.Top <= Me.PictureBox1.Top Then
  22.                         Ylocation = upbound
  23.                         Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Top, 100, 100)
  24.                     End If
  25.  
  26.                 Case Keys.A
  27.                     Me.PictureBox2.SetBounds(XLocation - Me.ComboBox1.Text, Ylocation, 100, 100)
  28.                     If Me.PictureBox2.Left <= Me.PictureBox1.Left Then
  29.                         Me.PictureBox2.SetBounds(Me.PictureBox1.Left, Ylocation, 100, 100)
  30.                     End If
  31.  
  32.                 Case Keys.D
  33.                     Me.PictureBox2.SetBounds(XLocation + Me.ComboBox1.Text, Ylocation, 100, 100)
  34.                     If Me.PictureBox2.Right >= Me.PictureBox1.Right Then
  35.                         Me.PictureBox2.SetBounds(Me.PictureBox1.Right - 100, Ylocation, 100, 100)
  36.                     End If
  37.  
  38.                 Case Keys.S
  39.                     Me.PictureBox2.SetBounds(XLocation, Ylocation + Me.ComboBox1.Text, 100, 100)
  40.                     If Me.PictureBox2.Bottom >= Me.PictureBox1.Bottom Then
  41.                         Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Bottom - 100, 100, 100)
  42.                     End If
  43.             End Select
  44.  
  45.         End If
  46.         If ((msg.Msg = WM_KEYUP) Or (msg.Msg = WM_SYSKEYUP)) Then
  47.             If keyData = Keys.P Then
  48.                 MessageBox.Show("hi")
  49.             End If
  50.         End If
  51.  
  52.  
  53.         Return MyBase.ProcessCmdKey(msg, keyData)
  54.     End Function
  55.  
Help.....what is the problem with KeyUp? / . \
It didnt respon when i press & release the P button on keyboard>.<

P.S. i searched nearly ALL post in here......

Thanks~! >.<
Feb 11 '07 #1
9 2581
Killer42
8,435 Expert 8TB
What debugging have you tried?

For example, have you checked what values are present, to see why they don't match what you code expects? Stepping through the code and examining variable values just before the code makes a decision based on them is usually a good way of working out what's going on.

For that matter, do you know whether control is actually entering this routine?
Feb 12 '07 #2
I have tried debugging
i checked the value but there would be a problem
I need to 'release' the button ( you cannot hold a keyboeard button while you move your mouse to check the code....)
so....
i think there is no way to test the WM_KeyUp..i think

(The value of WM_KeyUP at there while i release the button is 256 , whiich is definetly the value of the WM_KeyDomn if i set the breakpoint at there = =)

I need to see how people use the WM_KEYUP
WOuld you kindly show me how a workable function of WM_KEYUP?

Thanks...
Feb 12 '07 #3
Killer42
8,435 Expert 8TB
I don't think I can help directly, as I work in VB6 and this appears to be structured quite differently. I would have simply coded in the KeyDown and KeyUp events. :)

What I would recommend trying first is commenting out the entire routine (or creating a test program - this is probably simpler) and inserting a Debug.Print of msg and KeyData. Then run it, press your keys, and see what comes out. That should tell you whether you're testing for the correct values.
Feb 12 '07 #4
maybe i just turn to use keyup and keydown =.=
but i just find out that keyup/keydown need an object ( like textbox1 etc)
to process

how can i use keyup/keydown like 'Overrides' event?

(I just want to move a picturebox via keyboard ....like a real game
i really tried searching the web for game code but nothing help = =
could u please show me some example?)

Thanks for your replys.....thought not yet really helpful but
thanks for your advice
Feb 12 '07 #5
balid
18
Raiden1985,

Have you confirmed that that msg.msg value being passed matches your keyUp values or what the value of keyData is?

That least that's where I would start.

If you don't mind me asking, is this for an assignment? Because it seems like it would be a lot easier to use the KeyUp and KeyDown events as Killer42 pointed out.
Feb 12 '07 #6
Killer42
8,435 Expert 8TB
maybe i just turn to use keyup and keydown =.=
but i just find out that keyup/keydown need an object ( like textbox1 etc)
to process

how can i use keyup/keydown like 'Overrides' event?

(I just want to move a picturebox via keyboard ....like a real game
i really tried searching the web for game code but nothing help = =
could u please show me some example?)

Thanks for your replys.....thought not yet really helpful but
thanks for your advice
Well, to be honest, I have never before heard of "Overrides". VB6 and VB.Net really are quite different languages in many ways. So I can't say whether it's better or worse than the way I would have coded it. There may be very good reasons not to use the KeyUp/KeyDown events. Or there might not - I wouldn't know.

One thing I do know (for VB6, at least) is that if you set the KeyPreview property of a form to True, then it gets first look at keypresses before any of the controls on the form.

Hm... have you tried posting your question in the .Net forum? Perhaps you'll find a better response there.

(Also, I'll see if I can get one or two other VB experts to jump in here - their .Net skills may be better than mine.)
Feb 12 '07 #7
willakawill
1,646 1GB
This function traps command keypresses and menu shortcuts. It is not going to trap normal keys like P, according to Microsoft anyway.
to quote them:
This method is called during message preprocessing to handle command keys. Command keys are keys that always take precedence over regular input keys. Examples of command keys include accelerators and menu shortcuts. The method must return true to indicate that it has processed the command key, or false to indicate that the key is not a command key. This method is only called when the control is hosted in a Windows Forms application or as an ActiveX control.
Feb 13 '07 #8
hariharanmca
1,977 1GB
Please take a look at my code....

Expand|Select|Wrap|Line Numbers
  1.     Const WM_KEYDOWN As Integer = &H100
  2.     Const WM_SYSKEYDOWN As Integer = &H104
  3.     Const WM_KEYUP As Integer = &H101
  4.     Const WM_SYSKEYUP As Integer = &H105
  5.  
  6.  
  7.     Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
  8.  
  9.  
  10.  
  11.         Dim XLocation As Integer = PictureBox2.Location.X
  12.         Dim Ylocation As Integer = PictureBox2.Location.Y
  13.  
  14.         If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
  15.  
  16.             Select Case (keyData)
  17.                 Case Keys.W
  18.                     Me.Timer2.Start()
  19.  
  20.                     Me.PictureBox2.SetBounds(XLocation, Ylocation - Me.ComboBox1.Text, 100, 100)
  21.                     If Me.PictureBox2.Top <= Me.PictureBox1.Top Then
  22.                         Ylocation = upbound
  23.                         Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Top, 100, 100)
  24.                     End If
  25.  
  26.                 Case Keys.A
  27.                     Me.PictureBox2.SetBounds(XLocation - Me.ComboBox1.Text, Ylocation, 100, 100)
  28.                     If Me.PictureBox2.Left <= Me.PictureBox1.Left Then
  29.                         Me.PictureBox2.SetBounds(Me.PictureBox1.Left, Ylocation, 100, 100)
  30.                     End If
  31.  
  32.                 Case Keys.D
  33.                     Me.PictureBox2.SetBounds(XLocation + Me.ComboBox1.Text, Ylocation, 100, 100)
  34.                     If Me.PictureBox2.Right >= Me.PictureBox1.Right Then
  35.                         Me.PictureBox2.SetBounds(Me.PictureBox1.Right - 100, Ylocation, 100, 100)
  36.                     End If
  37.  
  38.                 Case Keys.S
  39.                     Me.PictureBox2.SetBounds(XLocation, Ylocation + Me.ComboBox1.Text, 100, 100)
  40.                     If Me.PictureBox2.Bottom >= Me.PictureBox1.Bottom Then
  41.                         Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Bottom - 100, 100, 100)
  42.                     End If
  43.             End Select
  44.  
  45.         End If
  46.         If ((msg.Msg = WM_KEYUP) Or (msg.Msg = WM_SYSKEYUP)) Then
  47.             If keyData = Keys.P Then
  48.                 MessageBox.Show("hi")
  49.             End If
  50.         End If
  51.  
  52.  
  53.         Return MyBase.ProcessCmdKey(msg, keyData)
  54.     End Function
  55.  
Help.....what is the problem with KeyUp? / . \
It didnt respon when i press & release the P button on keyboard>.<

P.S. i searched nearly ALL post in here......

Thanks~! >.<

are you sure that KeyUp, KeyDown, and KeyPress are not working properly
OR
any one of this is not working
Feb 13 '07 #9
Killer42
8,435 Expert 8TB
This function traps command keypresses and menu shortcuts. It is not going to trap normal keys like P, according to Microsoft anyway.
to quote them: ...
I don't know, Will. That wording is a bit vague. It could indicate that whatever you decide to process here becomes, by definition, a "command key".

Raiden, I still think basic debugging skills will produce your answer in this case; step through code, use breakpoints/watches/whatever, and determine exactly what is happening, and check against what was intended.
Feb 13 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Keith Smith | last post by:
Ok, I have been researching this problem for the past two hours (at least!) and I just can't seem to figure it out. So I broke down and decided to post some code for some of you gurus to look at....
1
by: graeme g | last post by:
hi is it possible to catch a keyup event in a panel? as i don't seem to be able to do it... i've even created a message handler for WM_KEYUP in the WndProc procedure but nothing works :-( ...
2
by: ZS | last post by:
Hi, On a form , I'm trying to trap when a shift key is pressed. Can someone explain how the KeyUp,KeyDown and Key Press event works for Forms. Thanks -ZS
15
by: DavidS | last post by:
Have Visual Studio.NET installed on MS 2000 Professional OS laptop. No issue ever with web development and SQL connections. Purchased new laptop with XP Professional SP2!!!!!!!! & Visual...
0
by: WhiteWizard | last post by:
I have a windows app that requires I use the Microsoft Datagrid. My users would like to be able to select multiple rows using the Shift and Ctrl keys, and the datagrid has the selection...
4
by: Bob Homes | last post by:
In VB6, I used a system, which I loved, whereby I assigned a "helpId" to each menu item; that way, you could rest the cursor on the item (without actually running it) and then press F1 to get...
1
by: Frank O'Hara | last post by:
I think I'm losing my mind, granted it is kind of late here so... I'm trying to do some simple validation on the client as keys are pressed. The validation routine works well enough however I...
11
by: Ben | last post by:
Hello, I'm trying to catch the pressing of the left and right arrow keys through the KeyUp event, like so: public Form1() { InitializeComponent(); Form1.ActiveForm.KeyUp += new...
5
by: sklett | last post by:
I know that Panel (and most of it's derivitives) don't raise keyboard events. I *really* need to catch keyboard events though so I've been googling the topic and have found quite a few...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.