A couple noob questions

Discussion in 'Programming General' started by Blupig, Feb 20, 2008.

A couple noob questions
  1. Unread #1 - Feb 20, 2008 at 5:27 PM
  2. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    A couple noob questions

    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!
     
  3. Unread #2 - Feb 21, 2008 at 1:14 AM
  4. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    A couple noob questions

    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()
     
  5. Unread #3 - Feb 21, 2008 at 7:52 AM
  6. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    A couple noob questions

    Isn't it recommended to switch to SendMessage now because Sendkeys was deprecated in Vista?
     
  7. Unread #4 - Feb 21, 2008 at 8:38 AM
  8. Blupig
    Joined:
    Nov 23, 2006
    Posts:
    7,145
    Referrals:
    16
    Sythe Gold:
    1,609
    Discord Unique ID:
    178533992981594112
    Valentine's Singing Competition Winner Member of the Month Winner MushyMuncher Gohan has AIDS Extreme Homosex World War 3 I'm LAAAAAAAME
    Off Topic Participant

    Blupig BEEF TOILET
    $5 USD Donor

    A couple noob questions

    I'm just learning .NET - I have no idea how to do that.
     
  9. Unread #5 - Feb 21, 2008 at 4:35 PM
  10. kharg0
    Joined:
    Feb 25, 2007
    Posts:
    131
    Referrals:
    0
    Sythe Gold:
    0

    kharg0 Active Member

    A couple noob questions

    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
     
  11. Unread #6 - Feb 22, 2008 at 7:41 PM
  12. Markizano
    Joined:
    Mar 2, 2006
    Posts:
    100
    Referrals:
    0
    Sythe Gold:
    0

    Markizano Active Member
    Banned

    A couple noob questions

    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.
     
  13. Unread #7 - Mar 1, 2008 at 3:36 PM
  14. skate4lifee
    Joined:
    Jul 22, 2007
    Posts:
    108
    Referrals:
    1
    Sythe Gold:
    0

    skate4lifee Active Member

    A couple noob questions

    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
     
  15. Unread #8 - Mar 1, 2008 at 6:35 PM
  16. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    A couple noob questions

    I dunno, is it?
     
< QUICK QUESTION-need help saveing | Looking For Visual C++ >

Users viewing this thread
1 guest


 
 
Adblock breaks this site