GetAsyncKeyState And Numpad?

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
12 posts Page 1 of 2
Contributors
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

GetAsyncKeyState And Numpad?
upperdrag
How do i use sendkeys on the numpad? i've tried "{NUMPAD1}" But it doesnt work! Is there a way to sendkeys numpad? Oh and is GetAsyncKeyState Stable? Because i've been trying to run it but it keeps messing up. Any code to sendkeys numpad? Thanks a ton

And how do i make hotkeys like ctrl+q?
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: GetAsyncKeyState And Numpad?
clanc789
The hotkeys IN your program? Of sendkeys to create the hotkey?
Practice makes perfect!

VIP since: 6-10-2011
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

Re: GetAsyncKeyState And Numpad?
upperdrag
Sendkeys the numpad numbers and hotkeys like alt+q and stuff..
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: GetAsyncKeyState And Numpad?
clanc789
The alt+q is that also a sendkey or a hotkey in YOUR program to activate the sendkeys?
Practice makes perfect!

VIP since: 6-10-2011
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: GetAsyncKeyState And Numpad?
mandai
The numpad question has been asked before: viewtopic.php?f=32&t=6275&start=0

GetAsyncKeyState is very reliable if you use it correctly.

RegisterHotKey is a good way to assign hotkeys across different programs; alternatively you could use GetAsyncKeyState for this purpose but it would mean extra work.
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

Re: GetAsyncKeyState And Numpad?
upperdrag
Heyy.. thanka for the replies... and about the getasynckeystate, i want to create a hotkey called 'alt+q' so when the userpresses alt+q, it will show a message, getasyncketstate(key
s.alt+keys.q) doesnt work...
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: GetAsyncKeyState And Numpad?
mandai
If you want to do that with GetAsyncKeyState you could use this code as an example:
Code: Select all
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 100
        Timer1.Enabled = True
    End Sub

    <DllImport("user32.dll")> Shared Function GetAsyncKeyState(ByVal vKey As Integer) As Short
    End Function

    Dim isDown As Boolean = False 'stops the message appearing until the keys are released/pressed again

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Dim leftAltDown As Short = GetAsyncKeyState(Keys.LMenu)
        Dim qDown As Short = GetAsyncKeyState(Keys.Q)

        If leftAltDown = -32768 And qDown = -32768 And Not isDown Then
            isDown = True
            MsgBox("Left Alt and Q are down")
        ElseIf leftAltDown = 0 And qDown = 0 And isDown Then
            isDown = False
        End If
    End Sub
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

Re: GetAsyncKeyState And Numpad?
upperdrag
Wow.. thanks for that! now.. for this code
Code: Select all
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP As Long = &H2
Private Const KEYEVENTF_EXTENDEDKEY As Long = &H1

Const VK_MENU = &H12 'ALT
Const VK_NUMPAD0 = &H60

Private Sub PressKey
  keybd_event VK_NUMPAD0, 0, KEYEVENTF_KEYUP, 0  ' release 0
  keybd_event VK_NUMPAD0, 0, 0, 0  ' press 3
End Sub
how can i tweak this so it works for other numpads too? How do i modify so like when i press f5, it will push numpad 2 and when i press f4 it will push numpad 3...? Is it possible for you to type out the code so that when i pressed f5 it will push numpad 2, f4 it will push numpad 3 and possibly roughly explain it? Thanks a lot mandai!



Btw i dont really understand the
Code: Select all
If leftAltDown = -32768 And qDown = -32768 And Not isDown Then
What is -32768?
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

Re: GetAsyncKeyState And Numpad?
upperdrag
Sigh... nvm i've found the solution...
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: GetAsyncKeyState And Numpad?
MrAksel
-32768 is the min value for the Int16, aka Short, data type. GetAsyncKeyState returns -32768 if the key is pressed.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
12 posts Page 1 of 2
Return to “Tutorial Requests”