Joystick Name?

Blitz3D Forums/Blitz3D Beginners Area/Joystick Name?

_PJ_(Posted 2009) [#1]
Does anyone happen to know of a .dll and how to use it (Or any other method, I hjust figured it would most likely be a .dll) that can obtain the name of a joystick/controller?


GfK(Posted 2009) [#2]
A guy called 'Pepsi' did one years ago so you might check the toolbox or something. Not sure if its still around anywhere, though.

[edit] Oh, actually I have it sat on my hard drives among 8 years worth of backups. Not sure it'd be 'proper' to upload it though since it isn't mine to do so with.

If Pepsi OKs it I'll maybe make it available somewhere.


_PJ_(Posted 2009) [#3]
Thanks GfK, yeah I remember Pepsi did a LOT of joystick stuff. I'll have another look over the toolbox and code archives int he meantime :D


SLotman(Posted 2009) [#4]
You dont need a dll for that - you can retrieve the joystick name and more (like Vendor ID and Product ID) just using Windows API call "joyGetDevCaps", just google it and it shouldn't be too hard to use it.


Ginger Tea(Posted 2009) [#5]
i guess knowing the joypad name makes it easier in supporting multiple types of button layouts without resorting to configuration screnes

if microsoft 360 joypad use this config
if ps3 joypad use this config
if logic3 use this config
if saitek use this config
etc
i guess youd need to know the joypads themselves to make sure it works right (not that im saying you need to buy every stick under the sun)


_PJ_(Posted 2009) [#6]
Exactly, GingerTea that's where I'm headed with this! :)

SLotman...
You dont need a dll for that - you can retrieve the joystick name and more (like Vendor ID and Product ID) just using Windows API call "joyGetDevCaps", just google it and it shouldn't be too hard to use it

Okay, you're talking to an idiot here.. how can I make a Windows API call without a DLL?


Stevie G(Posted 2009) [#7]
I think you're asking for trouble if you're going to hard code pad configurations based on their names. What happens when a new pad comes out that your app doesn't recognise or there is one you didn't support etc..

If your going to support joypads then you should support them ALL ( analogue & digital ) by letting the user configure them as they like, the name is irrelevant IMO.

Stevie


GfK(Posted 2009) [#8]
I agree with Stevie G.

Its useful to the player if you can display the joystick name in situations where there might be several connected to the PC and they want to select a specific one to use.

As for storing a separate joystick configuration based on its name - forget it. There are millions. And a lot of them are "Generic Gamepad" kind of thing anyway.


SLotman(Posted 2009) [#9]
how can I make a Windows API call without a DLL?

Userlibs :)

Of course you will actually be accessing a dll, but one from windows... you don't need to create/compile a dll yourself.

Its useful to the player if you can display the joystick name in situations where there might be several connected to the PC and they want to select a specific one to use.

As for storing a separate joystick configuration based on its name - forget it. There are millions. And a lot of them are "Generic Gamepad" kind of thing anyway.


Pretty much this is what I used it for... but also for identifying which joystick is a x360 (based on PId and VId, not on names) - so I can treat them with my x360 userlib instead of Blitz internal commands ;)


Stevie G(Posted 2009) [#10]
Pretty much this is what I used it for... but also for identifying which joystick is a x360 (based on PId and VId, not on names) - so I can treat them with my x360 userlib instead of Blitz internal commands ;)



Just curious but what features does a x360 pad have that others don't which requires a userlib?


Ginger Tea(Posted 2009) [#11]
afaik none
the dpad is listed as a hat (and last i tried blitz wont nativly see it)
the triggers are Z and not 11/12 or whatever, so using both buttons at the same time isnt an option ... pitty
and other buttons MIGHT be in a different order compared to a 'typical' pc pad, ive only compared with a ps3 clone

so unless it fixes the joyhat issues and allows both triggers then im in the dark as i was before finding out it existed ;)

edit:
unless it supports the chatpad thingie?
edit:
Library to read and control XBOX 360 joysticks. With this lib you can even make them vibrate.



_PJ_(Posted 2009) [#12]

Of course you will actually be accessing a dll, but one from windows... you don't need to create/compile a dll yourself



Thanks, I guess I shoulda been more specific originally, the whole userlibs/decals/dll thingy is all the same to me :D

I'll give it a try googling then and see what I can find!


_PJ_(Posted 2009) [#13]
Okay.,.. I am not good at this.

I have managed to obtain the following info on joyGetDevCaps() from MSDN,


joyGetDevCaps(
  UINT_PTR  uJoyID, 
  LPJOYCAPS pjc,    
  UINT      cbjc    
);



typedef struct { 
    WORD wMid; 
    WORD wPid; 
    TCHAR szPname[MAXPNAMELEN]; 
    UINT wXmin; 
    UINT wXmax; 
    UINT wYmin; 
    UINT wYmax; 
    UINT wZmin; 
    UINT wZmax; 
    UINT wNumButtons; 
    UINT wPeriodMin; 
    UINT wPeriodMax; 
    UINT wRmin; 
    UINT wRmax; 
    UINT wUmin; 
    UINT wUmax; 
    UINT wVmin; 
    UINT wVmax; 
    UINT wCaps; 
    UINT wMaxAxes; 
    UINT wNumAxes; 
    UINT wMaxButtons; 
    TCHAR szRegKey[MAXPNAMELEN]; 
    TCHAR szOEMVxD[MAX_JOYSTICKOEMVXDNAME]; 
} JOYCAPS;


I understand a 'Structure' to be equivalent in C to a Blitz 'Custom Type', however, I am not sure how to actually extract the 'fields'.

I've gotten only so far with the Decls:
.lib "WinAPI.dll"
GetController(uJoyID,pjc,cbjc):"joyGetDevCaps"

(Which I'm totally proud of the fact the function shows up in the Blitz IDE, tregardless of it working or not!!!)

To test this, I made the extremely simple bb code:

Print GetController(0,0,0)


Which results in an "Illegal Type Conversion".
I'm guessing it's because I need some form of syntax to point to the fields I want, not just leave the parameters as they are, but I have no clue how to go about this.

Apologies for my complete ignorance, but any pointers would be really helpful!


_PJ_(Posted 2009) [#14]
This discussion has changed to a WinAPI discussion, so I've slapped in a new topic in the other forum. Please lock/delete or whatever is necessary :)


_PJ_(Posted 2009) [#15]

You dont need a dll for that - you can retrieve the joystick name and more (like Vendor ID and Product ID) just using Windows API call "joyGetDevCaps", just google it and it shouldn't be too hard to use it.



Well, SLotman, it has proven too hard for me, It's been a coupla weeks now, but there's been no hit of replies.
ANYONE please, that knows more of decls, could you nudge me in the right direction some?


Warner(Posted 2009) [#16]
I replied here: http://www.blitzmax.com/Community/posts.php?topic=82836


_PJ_(Posted 2009) [#17]
Thanks Warner that really helps lots :)


Warner(Posted 2009) [#18]
O yes, and the error you got, is because the decl misses a % sign.
Wait, now I tried it, and I see, this should be the entire decl:
.lib "Winmm.dll"

GetController%(uJoyID*, pjc*, cbjc):"joyGetDevCapsA"

This is the code I used for using it:
jc = CreateBank(311)

uJoyID = CreateBank(2)

print "mmresult:"
Print GetController(uJoyID, jc, 310)

print "joyid:"
Print PeekShort(uJoyID, 0)

print "content jc:"
For i = 0 To 310
	b = PeekByte(jc, i)
	Write Chr$(b)
	If i Mod 30 = 29 Then Print
Next

Unf. I have no joystick, so it only returns a bunch of zeros here, but GetController return 165.


_PJ_(Posted 2009) [#19]
Alright, thanks for looking into it...

I'll get cracking on wha tI can and post back if I have any more trouble.


_PJ_(Posted 2009) [#20]
Thanks, Warner! At least GetController returns something. For me, it's "6"
Though I too get the lines of zeros regardless of what controllers are plugged in if at all.

------------

Edit:

Woohooo! I just found this! Dunno why I didnt see it before:
http://www.blitzbasic.com/codearcs/codearcs.php?code=840

Right now, it's giving me a MAV but I think I'm making progress!


Warner(Posted 2009) [#21]
That is a good find. I think that inside uJoyID there should be a number which tells the PC which joystick it should read. Maybe the ID's starts off from one ? I hope that fredborg's code in the archive helps, that would be quite nice.


_PJ_(Posted 2009) [#22]
The name isn't too helpful either as it gives the driver name, which is just the windows one for me.

Seems I bit off a bigger chunk than I can chew, but Il chom away at it ;)