Please take a look at my code.... - Const WM_KEYDOWN As Integer = &H100
-
Const WM_SYSKEYDOWN As Integer = &H104
-
Const WM_KEYUP As Integer = &H101
-
Const WM_SYSKEYUP As Integer = &H105
-
-
-
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
-
-
-
-
Dim XLocation As Integer = PictureBox2.Location.X
-
Dim Ylocation As Integer = PictureBox2.Location.Y
-
-
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
-
-
Select Case (keyData)
-
Case Keys.W
-
Me.Timer2.Start()
-
-
Me.PictureBox2.SetBounds(XLocation, Ylocation - Me.ComboBox1.Text, 100, 100)
-
If Me.PictureBox2.Top <= Me.PictureBox1.Top Then
-
Ylocation = upbound
-
Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Top, 100, 100)
-
End If
-
-
Case Keys.A
-
Me.PictureBox2.SetBounds(XLocation - Me.ComboBox1.Text, Ylocation, 100, 100)
-
If Me.PictureBox2.Left <= Me.PictureBox1.Left Then
-
Me.PictureBox2.SetBounds(Me.PictureBox1.Left, Ylocation, 100, 100)
-
End If
-
-
Case Keys.D
-
Me.PictureBox2.SetBounds(XLocation + Me.ComboBox1.Text, Ylocation, 100, 100)
-
If Me.PictureBox2.Right >= Me.PictureBox1.Right Then
-
Me.PictureBox2.SetBounds(Me.PictureBox1.Right - 100, Ylocation, 100, 100)
-
End If
-
-
Case Keys.S
-
Me.PictureBox2.SetBounds(XLocation, Ylocation + Me.ComboBox1.Text, 100, 100)
-
If Me.PictureBox2.Bottom >= Me.PictureBox1.Bottom Then
-
Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Bottom - 100, 100, 100)
-
End If
-
End Select
-
-
End If
-
If ((msg.Msg = WM_KEYUP) Or (msg.Msg = WM_SYSKEYUP)) Then
-
If keyData = Keys.P Then
-
MessageBox.Show("hi")
-
End If
-
End If
-
-
-
Return MyBase.ProcessCmdKey(msg, keyData)
-
End Function
-
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~! >.<
9 2581
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?
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...
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.
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
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.
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.)
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.
Please take a look at my code.... - Const WM_KEYDOWN As Integer = &H100
-
Const WM_SYSKEYDOWN As Integer = &H104
-
Const WM_KEYUP As Integer = &H101
-
Const WM_SYSKEYUP As Integer = &H105
-
-
-
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
-
-
-
-
Dim XLocation As Integer = PictureBox2.Location.X
-
Dim Ylocation As Integer = PictureBox2.Location.Y
-
-
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
-
-
Select Case (keyData)
-
Case Keys.W
-
Me.Timer2.Start()
-
-
Me.PictureBox2.SetBounds(XLocation, Ylocation - Me.ComboBox1.Text, 100, 100)
-
If Me.PictureBox2.Top <= Me.PictureBox1.Top Then
-
Ylocation = upbound
-
Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Top, 100, 100)
-
End If
-
-
Case Keys.A
-
Me.PictureBox2.SetBounds(XLocation - Me.ComboBox1.Text, Ylocation, 100, 100)
-
If Me.PictureBox2.Left <= Me.PictureBox1.Left Then
-
Me.PictureBox2.SetBounds(Me.PictureBox1.Left, Ylocation, 100, 100)
-
End If
-
-
Case Keys.D
-
Me.PictureBox2.SetBounds(XLocation + Me.ComboBox1.Text, Ylocation, 100, 100)
-
If Me.PictureBox2.Right >= Me.PictureBox1.Right Then
-
Me.PictureBox2.SetBounds(Me.PictureBox1.Right - 100, Ylocation, 100, 100)
-
End If
-
-
Case Keys.S
-
Me.PictureBox2.SetBounds(XLocation, Ylocation + Me.ComboBox1.Text, 100, 100)
-
If Me.PictureBox2.Bottom >= Me.PictureBox1.Bottom Then
-
Me.PictureBox2.SetBounds(XLocation, Me.PictureBox1.Bottom - 100, 100, 100)
-
End If
-
End Select
-
-
End If
-
If ((msg.Msg = WM_KEYUP) Or (msg.Msg = WM_SYSKEYUP)) Then
-
If keyData = Keys.P Then
-
MessageBox.Show("hi")
-
End If
-
End If
-
-
-
Return MyBase.ProcessCmdKey(msg, keyData)
-
End Function
-
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
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 :-(
...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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....
|
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...
|
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...
| |