Announcement

Collapse
No announcement yet.

Anyone familiar with VB?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Anyone familiar with VB?

    I have recently started using iTunes instead of Winamp. And so, I have been working on a project in Visual Basic 6.0 to create a remote control for it. I have a working model consisting of buttons. However, I would like to assign a hotkey or combination hotkey to some of the buttons, enabling me to control iTunes from within a game. Heres a snippet of the code assigned to a button:

    Code:
    Private Sub UpVol_Click()
        Dim iTunes As iTunesApp
        iTunesApp.SoundVolume = iTunesApp.SoundVolume + 10
        Set iTunes = Nothing
    End Sub
    So my question is how do I go about assigning say 'Alt + Numpad+' to this button?

  • #2
    I can change mine with my Windows wireless keyboard

    it has play/stop, next, previous on it, etc on it so i just hit those and it chagnes
    1:Hydride> who we play next week
    1:ReNdErED> Pandora
    1:ReNdErED> gulp
    1:ReNdErED> if i see Ease im shiftin across map

    1:Hydride> best feeling EVER
    1:Hydride> its like if you get sacked and when the pain goes away feeling x 999999999999999999999999
    1:cranium> uve obviously never fucked a plastic bag filled with jelly inbetween the couch cushions
    1:menelvagor> ROOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOFL
    1:cranium> talk about a feeling

    Comment


    • #3
      Originally posted by Mr. Peanuts
      I have recently started using iTunes instead of Winamp. And so, I have been working on a project in Visual Basic 6.0 to create a remote control for it. I have a working model consisting of buttons. However, I would like to assign a hotkey or combination hotkey to some of the buttons, enabling me to control iTunes from within a game. Heres a snippet of the code assigned to a button:

      Code:
      Private Sub UpVol_Click()
          Dim iTunes As iTunesApp
          iTunesApp.SoundVolume = iTunesApp.SoundVolume + 10
          Set iTunes = Nothing
      End Sub
      So my question is how do I go about assigning say 'Alt + Numpad+' to this button?
      You have a number of options. I'm assuming you want the keypresses to work in whatever program you are using.

      If you are intending to get it to detect keypresses outside of the vb form you will either need to use hooking (im too newb to understand it) , wirte your own keyboard driver

      or go for the easy (noob) way of using windowsAPI: GetAsyncKeyStateGet()

      http://msdn.microsoft.com/library/de...nckeystate.asp

      http://msdn.microsoft.com/library/de...alKeyCodes.asp

      I created this on a laptop so my keys are a bit funny so u might have to play with the codes :P And for the newb hackers amoung u - you can have fun changing this into a keylogger ez and yes i suck at vb.

      Code:
      'u need a timer on your vb form called timer1 with an interval of 1-10 milliseconds ( depends how responsive u want it)
      'LOAD WINDOWS API FUNCTIONS
      Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
      Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
      Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal uCode As Integer, ByVal uMapType As Integer) As Integer
      
      
      Private Sub Timer1_Timer()
      For i = 1 To 255 'check each of the 255 virtual keys to see if they have been pressed 
      result = 0
      result = GetAsyncKeyState(i) 'get state of key
        If result = -32767 Then ' the key has been pressed
          If GetKeyState(18) And Chr(MapVirtualKey(i, 2)) = "[" Then
         ' check if alt key (vk_menu) is pressed and "[" key (i dont have numpad you can change this to a "+" )
          MsgBox "hello there" ' Display annoying popup box (optional :P)
        
          UpVol_Click() 'DO ITUNES ACCTION HERE
          End If
        End If
      Next i
      End Sub
           
      '+++++++++++++++++++++++++++++++++++
      I can email you working code if u cant get this to work.
      Last edited by Doc Flabby; 02-09-2006, 11:35 AM.
      Rediscover online gaming. Get Subspace

      Mantra-Slider> you like it rough
      Kitty> true

      I girl with BooBiez> OH I GET IT U PRETEND TO BE A MAN


      Flabby.tv - The Offical Flabby Website

      Comment


      • #4
        Wow! Thanks a lot man, this really helps, I think I'll be good to work the rest of the keys out.

        I would bend over for you if I could.






        Comment


        • #5
          edit: actually, how do these VK_ keys work? I've tried to use Numpad8 to change to previous track

          I've tried this but it didn't work:
          Code:
          For i = 1 To 255 'check each of the 255 virtual keys to see if they have been pressed
          result = 0
          result = GetAsyncKeyState(i) 'get state of key
            If result = -32767 Then ' the key has been pressed
              If GetKeyState(18) And Chr(MapVirtualKey(i, 2)) = "VK_NUMPAD8" Then
              Prev_Click
              End If
            End If
          Next i
          Edit: now only the volume hotkeys are working
          Last edited by Mr. Peanuts; 02-09-2006, 01:00 PM.

          Comment


          • #6
            Originally posted by Mr. Peanuts
            edit: actually, how do these VK_ keys work? I've tried to use Numpad8 to change to previous track

            I've tried this but it didn't work:
            Code:
            For i = 1 To 255 'check each of the 255 virtual keys to see if they have been pressed
            result = 0
            result = GetAsyncKeyState(i) 'get state of key
              If result = -32767 Then ' the key has been pressed
                If GetKeyState(18) And Chr(MapVirtualKey(i, 2)) = "VK_NUMPAD8" Then
                Prev_Click
                End If
              End If
            Next i
            I've made a bit of a mess of this line because of my laptop keyboard being weird.

            Code:
            If GetKeyState(18) And Chr(MapVirtualKey(i, 2)) = "]" Then
            MapVirtualKey() convert the VK_NUMPAD8 to its real key so would be "8"

            VK_NUMPAD8 is a constant it is actually a number

            VK_NUMPAD8 (68)
            Numeric keypad 8 key

            68 is a hex number so => 104

            You need to change it to

            Code:
            If GetKeyState(18) And i = 104 Then
            this might not work as codes differ between keyboards

            if you wanna find the right code using this

            Code:
            For i = 1 To 255 'check each of the 255 virtual keys to see if they have been pressed
            result = 0
            result = GetAsyncKeyState(i) 'get state of key
              If result = -32767 Then ' the key has been pressed
                debug.print i 'display key code
              End If
            Next i
            Rediscover online gaming. Get Subspace

            Mantra-Slider> you like it rough
            Kitty> true

            I girl with BooBiez> OH I GET IT U PRETEND TO BE A MAN


            Flabby.tv - The Offical Flabby Website

            Comment


            • #7
              Ah, I have it working however it seems to take ages to respond.

              Should I create differnet timers for each hotkey?

              edit: tried that and it seems to be responding quicker.
              Last edited by Mr. Peanuts; 02-09-2006, 01:32 PM.

              Comment


              • #8
                Originally posted by Mr. Peanuts
                Ah, I have it working however it seems to take ages to respond.

                Should I create differnet timers for each hotkey?

                edit: tried that and it seems to be responding quicker.
                or reduce the interval on the timer to 1 millisecond

                if u add too many timers that will slow it down too :P
                Rediscover online gaming. Get Subspace

                Mantra-Slider> you like it rough
                Kitty> true

                I girl with BooBiez> OH I GET IT U PRETEND TO BE A MAN


                Flabby.tv - The Offical Flabby Website

                Comment


                • #9
                  just tried that, still seems a tad sluggish, but it works nonetheless thanks

                  editxdzda: i notice its only the first code for VolUp that isnt sluggish in response. any thoughts?
                  Last edited by Mr. Peanuts; 02-09-2006, 01:48 PM.

                  Comment


                  • #10
                    Originally posted by Mr. Peanuts
                    just tried that, still seems a tad sluggish, but it works nonetheless thanks

                    editxdzda: i notice its only the first code for VolUp that isnt sluggish in response. any thoughts?
                    post your code up and ill have a look :P
                    Rediscover online gaming. Get Subspace

                    Mantra-Slider> you like it rough
                    Kitty> true

                    I girl with BooBiez> OH I GET IT U PRETEND TO BE A MAN


                    Flabby.tv - The Offical Flabby Website

                    Comment


                    • #11
                      Ok, heres the code in its entririty:

                      Code:
                      Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
                      Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
                      Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal uCode As Integer, ByVal uMapType As Integer) As Integer
                      
                      Private Sub DownVol_Click()
                          Dim iTunes As iTunesApp
                          iTunesApp.SoundVolume = iTunesApp.SoundVolume - 10
                          Set iTunes = Nothing
                      End Sub
                      
                      Private Sub UpVol_Click()
                          Dim iTunes As iTunesApp
                          iTunesApp.SoundVolume = iTunesApp.SoundVolume + 10
                          Set iTunes = Nothing
                      End Sub
                      
                      Private Sub Prev_Click()
                           Dim iTunes As iTunesApp
                           Set iTunes = New iTunesApp
                           iTunes.PreviousTrack
                           Set iTunes = Nothing
                      End Sub
                      
                      Private Sub Next_Click()
                           Dim iTunes As iTunesApp
                           Set iTunes = New iTunesApp
                           iTunes.NextTrack
                           Set iTunes = Nothing
                      End Sub
                      
                      Private Sub Play_Click()
                           Dim iTunes As iTunesApp
                           Set iTunes = New iTunesApp
                           iTunes.Play
                           Set iTunes = Nothing
                      End Sub
                      
                      Private Sub Pause_Click()
                           Dim iTunes As iTunesApp
                           Set iTunes = New iTunesApp
                           iTunes.Pause
                           Set iTunes = Nothing
                      End Sub
                      
                      'HERE WE HAVE KEYPRESSES
                      'NUMPAD PLUS - UPVOL
                      Private Sub Timer1_Timer()
                      For i = 1 To 255 'check each of the 255 virtual keys to see if they have been pressed
                      result = 0
                      result = GetAsyncKeyState(i) 'get state of key
                        If result = -32767 Then ' the key has been pressed
                          If GetKeyState(18) And i = 107 Then
                         ' check if alt key (vk_menu) is pressed and "[" key (i dont have numpad you can change this to a "+" )
                        
                          UpVol_Click
                          End If
                        End If
                      Next i
                      
                      'NUMPAD MINUS - DOWNVOL
                      For i = 1 To 255
                      result = 0
                      result = GetAsyncKeyState(i)
                        If result = -32767 Then
                          If GetKeyState(18) And i = 109 Then
                         
                        
                          DownVol_Click
                          End If
                        End If
                      Next i
                      
                      'NUMPAD 8 - PREV
                      For i = 1 To 255
                      result = 0
                      result = GetAsyncKeyState(i)
                        If result = -32767 Then
                          If GetKeyState(18) And i = 104 Then
                          Prev_Click
                          End If
                        End If
                      Next i
                      
                      'NUMPAD 2 - NEXT
                      For i = 1 To 255
                      result = 0
                      result = GetAsyncKeyState(i)
                        If result = -32767 Then
                          If GetKeyState(18) And i = 98 Then
                          Next_Click
                          End If
                        End If
                      Next i
                      
                      'NUMPAD 5 - PAUSE
                      For i = 1 To 255
                      result = 0
                      result = GetAsyncKeyState(i)
                        If result = -32767 Then
                          If GetKeyState(18) And i = 101 Then
                          Pause_Click
                          End If
                        End If
                      Next i
                      
                      'NUMPAD 0 - PLAY
                      For i = 1 To 255
                      result = 0
                      result = GetAsyncKeyState(i)
                        If result = -32767 Then
                          If GetKeyState(18) And i = 96 Then
                          Play_Click
                          End If
                        End If
                      Next i
                      
                      End Sub

                      Comment


                      • #12
                        Code:
                        Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
                        Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
                        Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal uCode As Integer, ByVal uMapType As Integer) As Integer
                        
                        Private Sub DownVol_Click()
                            Dim iTunes As iTunesApp
                            iTunesApp.SoundVolume = iTunesApp.SoundVolume - 10
                            Set iTunes = Nothing
                        End Sub
                        
                        Private Sub UpVol_Click()
                            Dim iTunes As iTunesApp
                            iTunesApp.SoundVolume = iTunesApp.SoundVolume + 10
                            Set iTunes = Nothing
                        End Sub
                        
                        Private Sub Prev_Click()
                             Dim iTunes As iTunesApp
                             Set iTunes = New iTunesApp
                             iTunes.PreviousTrack
                             Set iTunes = Nothing
                        End Sub
                        
                        Private Sub Next_Click()
                             Dim iTunes As iTunesApp
                             Set iTunes = New iTunesApp
                             iTunes.NextTrack
                             Set iTunes = Nothing
                        End Sub
                        
                        Private Sub Play_Click()
                             Dim iTunes As iTunesApp
                             Set iTunes = New iTunesApp
                             iTunes.Play
                             Set iTunes = Nothing
                        End Sub
                        
                        Private Sub Pause_Click()
                             Dim iTunes As iTunesApp
                             Set iTunes = New iTunesApp
                             iTunes.Pause
                             Set iTunes = Nothing
                        End Sub
                        
                        'HERE WE HAVE KEYPRESSES
                        
                        Private Sub Timer1_Timer()
                        For i = 1 To 255 'check each of the 255 virtual keys to see if they have been pressed
                        result = 0
                        result = GetAsyncKeyState(i) 'get state of key
                          If result = -32767 Then ' the key has been pressed
                            stateOfAlt = GetKeyState(18) 
                            If stateOfAlt And i = 107 Then: UpVol_Click 'NUMPAD PLUS - UPVOL
                            If stateOfAlt And i = 109 Then: DownVol_Click 'NUMPAD MINUS - DOWNVOL
                            If stateOfAlt And i = 104 Then: Prev_Click 'NUMPAD 8 - PREV
                            If stateOfAlt And i = 98  Then: Next_Click 'NUMPAD 2 - NEXT
                            If stateOfAlt And i = 101 Then: Pause_Click 'NUMPAD 5 - PAUSE
                            If stateOfAlt And i = 96  Then: Play_Click 'NUMPAD 0 - PLAY
                          End If
                        Next i
                        
                        
                        End Sub
                        im at work so i cant check if it works but give it a try
                        Rediscover online gaming. Get Subspace

                        Mantra-Slider> you like it rough
                        Kitty> true

                        I girl with BooBiez> OH I GET IT U PRETEND TO BE A MAN


                        Flabby.tv - The Offical Flabby Website

                        Comment


                        • #13
                          Wow, so helpful, this works perfectly now! Thanks a lot! :wub: :wub:

                          Comment


                          • #14
                            Originally posted by Mr. Peanuts

                            I would bend over for you if I could.






                            HAHAHA

                            Comment


                            • #15
                              you know how i roll

                              Comment

                              Working...
                              X