• Log in or sign up for an account here: https://www.sythe.org/login

A couple noob questions

Blupig

BEEF TOILET

$5 USD Donor
Joined
Nov 23, 2006
Sythe Gold
1,609
Messages
7,145
Age
33
Location
Canada
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
1. How can I make it so something happens when a key is pressed? In VB6 it's like this (without the declaration):
Code:
If GetAsyncKeyState(vbKeynanana) Then
stuff.happens
End If

2. What's the sendkeys format in .NET

I'll be updating this when I have more questions. Thanks everyone!
 
Member of the Month Winner
Sythe's 10th Anniversary
Use MSDN.

For your first question: What I did was save a blank keyboard state, and compare the keyboard state to check the difference, and then you have whether a key is pressed. I got the method from using XNA.

For your second question, use SendKeys.Send()
 
Isn't it recommended to switch to SendMessage now because Sendkeys was deprecated in Vista?
 
Valentine's Singing Competition Winner
Sythe Awards 2015 Winner
Sythe Awards 2016 Winner
Sythe Awards 2020 Winner
Member of the Month Winner
MushyMuncher
Gohan has AIDS
Extreme Homosex
World War 3
I'm LAAAAAAAME
Discord Verified
Off Topic Participant
Use MSDN.

For your first question: What I did was save a blank keyboard state, and compare the keyboard state to check the difference, and then you have whether a key is pressed. I got the method from using XNA.

I'm just learning .NET - I have no idea how to do that.
 
Code:
sendkeys.send (keys.YOUR KEY!)
if u didnt no already jst makin sure

and if u want it to detect a key press add this to form keypress property..
Code:
If e.keycode = Keys.YourKey Then
            'W/E u want it to do wen pressed
        End If

Code:
 Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.BrowserBack Then
            WebBrowser1.GoBack()
        End If
    End Sub
 
for this you need a button named Button1
just keep things simple like you had it:
Code:
Friend Class Form1
 Inherits System.Windows.Forms.Form

 Private Declare Function GetAsyncKeyState Lib "User32" (ByVal vbKey As Long) As Integer

 Private Sub Button1_Click(ByVal Sender As Object, ByVal eArgs As EventArgs) Handles Button1.Click
  If GetAsyncKeyState(32) Then
   MsgBox("The space bar was pressed")
  End If
 End Sub

End Class

However, I experimented with the return values of GetAsyncKeyState.
For this you need a label named Label1 and a timer named Timer1
Here an application to this result:
Code:
Friend Class Form1
 Inherits System.Windows.Forms.Form

 Private Declare Function GetAsyncKeyState Lib "User32" (ByVal vbKey As Long) As Integer


 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  Label1.Text = GetAsyncKeyState(32).ToString
  If Label1.Text = "0" Then
   Label1.Text &= vbNewLine & "The key is released."
  ElseIf Label1.Text = "1" Then
   Label1.Text &= vbNewLine & "The key was pressed."
  ElseIf Label1.Text = "-32767" Then
   Label1.Text &= vbNewLine & "The key is down."
  ElseIf Label1.Text = "-32768" Then
   Label1.Text &= vbNewLine & "The key has been pressed within the last 1000 milliseconds."
  End If
 End Sub

End Class
That's how you detect a keypress in VB.NET, but it works best with a timer with an interval from 300 to 500 ms.

And, just to verify, they are correct when they say that
Code:
SendKeys.Send(ByVal Keys As String, ByVal Control As System.Windows.Forms.Control, ByVal Wait As Boolean)
is the correct method to use when sending text to the open application that has input focus.
 
i haven't used visual basic in a while, but i'm pretty sure you can use GetAsyncKeyState. go to the form's key down property (not sure) and add this code.

Code:
if GetAsyncKeyState(keys.F1) then
messagebox.show("hello")
end if
 
Member of the Month Winner
Sythe's 10th Anniversary
Runescape Gamblingrunescape gambling
Back
Top