pinvoke function has unbalanced the stack?

Socarsky

Well-known member
Joined
Dec 27, 2012
Messages
173
Location
Jakarta/Indonesia
Programming Experience
Beginner
hatag.png
 
That is some fairly horrible code. Firstly, you're using VB6 signature for the GetAsyncKeyState function instead of VB.NET. Secondly, you're testing a number using an If statement when you should be testing a Boolean. Finally, as far as I can tell, you shouldn't be using GetAsyncKeyState at all. If you want to do something when the user presses a key then handle the KeyDown or KeyPress event of the form or the appropriate control.
 
Yes, I noticed my mistake that I am trying to solve this with a right one. By the way I have got that line of code for youtube to try it out on my side. Thanks for suggestions
 
This method looks none case-sensitive, it works with w whether its low or upper char. How do I make it with case-sensitive?

Public Class Form1
    Dim kacDefa As Integer = 0
    Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        If e.KeyValue = Keys.W Then
            kacDefa += 1
            Label1.Text = "W pressed " & kacDefa & " time(s)"
        End If
    End Sub
End Class
 
Hi,

You cannot differentiate case sensitivity in the KeyDown event but you can differentiate case sensitivity in the KeyPress event using the e.KeyChar property.

Hope that helps.

Cheers,

Ian
 
Hi,

You cannot differentiate case sensitivity in the KeyDown event but you can differentiate case sensitivity in the KeyPress event using the e.KeyChar property.

Hope that helps.

Cheers,

Ian
That's quite true, because KeyDown is about keys on the keyboard while KeyPress is about characters. Not all keys correspond to characters and not all characters are the product of a single key. That said, you can detect specific key combinations using KeyDown, e.g. Shift+W. Socarsky, to learn more about keyboard events, follow the Blog link in my signature and check out my post on the subject.
 
That's quite true, because KeyDown is about keys on the keyboard while KeyPress is about characters. Not all keys correspond to characters and not all characters are the product of a single key. That said, you can detect specific key combinations using KeyDown, e.g. Shift+W. Socarsky, to learn more about keyboard events, follow the Blog link in my signature and check out my post on the subject.
Got the topic in your blog and I started to read it. Here is the link: John McIlhinney's .NET Developer Blog: Keyboard Events in Windows Forms
 
Back
Top