Jump to content
Sign in to follow this  
gzuz

xbox 360 controller plugin.

Recommended Posts

gzuz

I dont know if anyone here knows anything about programming or not but i thought i might as well let you guys see what i have been working on, its a profile for an xbox 360 remote to be interface able with PT. Its still in the early stages as i only started working on it lastnight and the code is still very messy as i have been trying to figure out the best ways to pass statements to realmpt and have it accept them in the best way. Here is what i got so far :)

 

Imports Microsoft.Xna
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.GamerServices
Imports Microsoft.Xna.Framework.Content



Public Class xBox360Controller
    Public Const MOUSEEVENTF_LEFTDOWN = &H2
    Public Const MOUSEEVENTF_LEFTUP = &H4
    Public Const MOUSEEVENTF_RIGHTDOWN = &H8
    Public Const MOUSEEVENTF_RIGHTUP = &H10
    Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Dim skillcount = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim currentState As GamePadState = GamePad.GetState(PlayerIndex.One)


        If currentState.IsConnected Then
            '-------------------------------------Analogue Stick to Mouse--------------------------------
            If MousePosition.Y > 30 Then
                Mouse.SetPosition(x:=CInt(MousePosition.X + currentState.ThumbSticks.Right.X * 30), y:=CInt(MousePosition.Y - currentState.ThumbSticks.Right.Y * 30))
            Else
                Mouse.SetPosition(x:=MousePosition.X, y:=40)


            End If


            '-------------------------------------Trigger Click Functions--------------------------------
            'These functions map the xbox trigger to the click functions so you can run and use skills

            If currentState.Triggers.Right = 1 Then



                Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)

            ElseIf currentState.Triggers.Right = 0 Then

                Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)


            End If

            If currentState.Triggers.Left = ButtonState.Pressed = True Then
                Call mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)


            End If
            '----------------------------------Skill Functions----------------------------------------
            'Toggles through skill selection with right shoulder button
            Dim skillselect = 0
            If currentState.Buttons.LeftShoulder = ButtonState.Pressed Then
                skill(skillselect)
            End If

            '-----------------------------------Camera Functions--------------------------------------
            'Having trouble getting this to work atm but will continue on this after i get other functionality working




            '-------------------------------------------------PotionsFunctions-------------------------
            'These work fine to use potions but can get a bit laggy
            If currentState.DPad.Left = 1 Then
                potions(1)

            End If
            If currentState.DPad.Up = 1 Then
                potions(2)



            End If
            If currentState.DPad.Right = 1 Then
                potions(3)

            End If
        End If


    End Sub

    Private Sub xBox360Controller_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim currentState As GamePadState = GamePad.GetState(PlayerIndex.One)

        If currentState.IsConnected Then
            Dim clickcount = 0

            '--------------------------Change Weapon-------------------------
            If currentState.Buttons.Y = ButtonState.Pressed = True Then


                SendKeys.SendWait("w")
                SendKeys.Flush()



            End If

            '-------------------------Open Inventory----------------------------
            If currentState.Buttons.X = ButtonState.Pressed = True Then

                SendKeys.SendWait("v")
                SendKeys.Flush()

            End If



            '--------------------------Open Stats Page----------------------------
            If currentState.Buttons.B = ButtonState.Pressed = True Then

                SendKeys.SendWait("c")
                SendKeys.Flush()




            End If

            '-------------------------Skills Page---------------------------------
            If currentState.Buttons.A = ButtonState.Pressed = True Then

                SendKeys.SendWait("s")
                SendKeys.Flush()


            End If
        End If

    End Sub
    Private Sub potions(ByRef potno As Integer)
        Dim clickcount = 0
        '----------------Private function to send potions singularly instead of spamming key
        If clickcount = 0 Then
            SendKeys.Send(potno)
            clickcount = 1

        End If
    End Sub
    Private Sub skill(ByRef skillsel)
        skillcount = skillcount + 1
        If skillcount = 9 Then
            skillcount = 1
        End If

        SendKeys.SendWait(Chr(34) & "{F" & skillcount & "}" & Chr(34))
    End Sub
End Class

 

To use this code you must have XNA framework installed, when launching visual studio create a new windows application and add refferences to all of the xna framework modules.

Share this post


Link to post
Share on other sites
gzuz

im currently trying to use alternative methods to using timers for buttons funcs as they can be a bit laggy and are annoying to set a time interval rather than the cpu just queing the func and waiting on timer times.

Share this post


Link to post
Share on other sites
Barbellz

There is a program you can download and from there you can assign keyboard/mouse keys to a button/stick on the xbox360 controller, it might save time downloading it instead of making yourself :x

Share this post


Link to post
Share on other sites
JAI

Damn I was just about to make a thread regarding PT and controllers O.o

 

There is a program you can download and from there you can assign keyboard/mouse keys to a button/stick on the xbox360 controller, it might save time downloading it instead of making yourself :x

 

any sources, links on this? Would like to know more.

Share this post


Link to post
Share on other sites
gzuz

incremental skill switcher is partially a reason. Another is cos i would rather code something myself than download some crap from the internet and not have the experience.

Share this post


Link to post
Share on other sites
Barbellz

Damn I was just about to make a thread regarding PT and controllers O.o

 

There is a program you can download and from there you can assign keyboard/mouse keys to a button/stick on the xbox360 controller, it might save time downloading it instead of making yourself :x

 

any sources, links on this? Would like to know more.

 

http://xpadder.com/ is a decent start, pretty basic but very enjoyable

 

incremental skill switcher is partially a reason. Another is cos i would rather code something myself than download some crap from the internet and not have the experience.

Skill switching with xpadder is quite difficult indeed. Good luck mate, I hope you're able to make something nice :)!

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

News and Updates

×
×
  • Create New...