Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: VB express 2008 keyboard input.  (Read 13641 times)

0 Members and 1 Guest are viewing this topic.

gamerx365

    Topic Starter


    Adviser
  • Radda Radda!
  • Thanked: 1
    • Yes
    • Yes
  • Experience: Experienced
  • OS: Windows 10
VB express 2008 keyboard input.
« on: February 01, 2009, 07:31:33 PM »
I need to put keyboard input into my program, mostly letters and numbers. I have been using "If GetAsyncKeyState(65) Then" under a time but it's definitely not going to work out on this one. Sometimes I get a short delay and sometimes i get more than one instance. Anybody know how to fix this easily?

Thank you!

Bones92



    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: VB express 2008 keyboard input.
« Reply #1 on: February 03, 2009, 09:19:44 PM »
just use the Key_Press event?

gamerx365

    Topic Starter


    Adviser
  • Radda Radda!
  • Thanked: 1
    • Yes
    • Yes
  • Experience: Experienced
  • OS: Windows 10
Re: VB express 2008 keyboard input.
« Reply #2 on: February 04, 2009, 04:49:13 AM »
ok. can i have an example quick please? i never learned that one.

Bones92



    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: VB express 2008 keyboard input.
« Reply #3 on: February 04, 2009, 07:51:18 PM »
sure.

Code: [Select]
Public Class Form1

    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        MsgBox(e.KeyChar)
    End Sub

End Class

With this, when you press a keyboard key, it puts it in a messagebox  ;D

Good luck.

gamerx365

    Topic Starter


    Adviser
  • Radda Radda!
  • Thanked: 1
    • Yes
    • Yes
  • Experience: Experienced
  • OS: Windows 10
Re: VB express 2008 keyboard input.
« Reply #4 on: February 05, 2009, 07:52:42 PM »
Thanx. Do I need an imports line or anything? I get the error : "Event Keypress can not be found" under the last part of the private sub

Bones92



    Hopeful

  • Website Designer and Microcontroller Programmer
  • Thanked: 3
    • PIC Programming New Zealand
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: VB express 2008 keyboard input.
« Reply #5 on: February 05, 2009, 08:38:27 PM »
you are using 2008? I am not using any imports statments, however, you could try Imports System.Windows.Forms

ultimatum



    Intermediate
  • Thanked: 3
    Re: VB express 2008 keyboard input.
    « Reply #6 on: February 06, 2009, 08:09:21 PM »
    Quote
    System.Windows.Forms.KeyPressEventArgs

    Ye, it's using System.Windows.Forms so you need to add that line at the top of VB.
    Its not what you know, its what you can do that counts!

    gamerx365

      Topic Starter


      Adviser
    • Radda Radda!
    • Thanked: 1
      • Yes
      • Yes
    • Experience: Experienced
    • OS: Windows 10
    Re: VB express 2008 keyboard input.
    « Reply #7 on: February 08, 2009, 04:07:42 PM »
    Ive tried them and I'm still getting the same error. Anything else?

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: VB express 2008 keyboard input.
    « Reply #8 on: February 08, 2009, 04:16:30 PM »
    where are you pasting it?

    I was trying to dereference Null Pointers before it was cool.

    gamerx365

      Topic Starter


      Adviser
    • Radda Radda!
    • Thanked: 1
      • Yes
      • Yes
    • Experience: Experienced
    • OS: Windows 10
    Re: VB express 2008 keyboard input.
    « Reply #9 on: February 08, 2009, 04:37:41 PM »
    tried top line, and second line.

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: VB express 2008 keyboard input.
    « Reply #10 on: February 08, 2009, 04:38:30 PM »
    what file.... Is there anything in the file already?
    I was trying to dereference Null Pointers before it was cool.

    gamerx365

      Topic Starter


      Adviser
    • Radda Radda!
    • Thanked: 1
      • Yes
      • Yes
    • Experience: Experienced
    • OS: Windows 10
    Re: VB express 2008 keyboard input.
    « Reply #11 on: February 08, 2009, 05:33:20 PM »
    A couple lines of the old code and one section of the new... like this:

    Code: [Select]
    'Imports System.Windows.Forms.KeyPressEventArgs
    Imports System.Windows.Forms
    Public Class Form1
        Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal keyCode As Integer) As Short
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            'If GetAsyncKeyState(90) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_1.wav", AudioPlayMode.Background)
            If GetAsyncKeyState(88) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_2.wav", AudioPlayMode.Background)
            If GetAsyncKeyState(67) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_3.wav", AudioPlayMode.Background)

            If GetAsyncKeyState(65) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_4.wav", AudioPlayMode.Background)
            If GetAsyncKeyState(83) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_5.wav", AudioPlayMode.Background)
            If GetAsyncKeyState(68) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_6.wav", AudioPlayMode.Background)
            If GetAsyncKeyState(70) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_7.wav", AudioPlayMode.Background)
            If GetAsyncKeyState(71) Then My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_8.wav", AudioPlayMode.Background)
        End Sub

        Public Class Form1
            Private Sub Form1_KeyPress(ByVal sender As Object, ByVal z As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
                My.Computer.Audio.Play("C:\Documents and Settings\HP_Owner\Desktop\Samples\drum_1.wav", AudioPlayMode.Background)
            End Sub
        End Class
    End Class

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: VB express 2008 keyboard input.
    « Reply #12 on: February 08, 2009, 06:18:36 PM »
    don't paste the "Public Class Form1" or "End Class". Just the Sub.
    I was trying to dereference Null Pointers before it was cool.

    gamerx365

      Topic Starter


      Adviser
    • Radda Radda!
    • Thanked: 1
      • Yes
      • Yes
    • Experience: Experienced
    • OS: Windows 10
    Re: VB express 2008 keyboard input.
    « Reply #13 on: February 08, 2009, 06:39:03 PM »
    oh lol. i'm dumb. I don't even know how that got there. thanx lol.

    JokermanVB



      Newbie

      Re: VB express 2008 keyboard input.
      « Reply #14 on: March 20, 2009, 03:31:24 PM »
      well i read what was above and how you pick out the left, right, up, down arrows??