April 25, 2024, 04:54:39 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Where's my Joystick ..

Started by GWS, December 03, 2006, 12:24:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi folks,

I've got a problem getting 'DirectInput' to work.

It's not reporting any joystick attached, or detecting any GetKey depressions ..

Here's my little test program:

/*
Simple example of creating a 2D screen
*/

window w
int i,run

wstyle = @SIZE|@NOAUTODRAW
openwindow w,0,0,800,600,wstyle,0,"Joystick Test",&mainwindow

setwindowcolor w, rgb(0,0,100)

run = 1

IF ATTACHSCREEN(w, 800, 600, 32) < 0
ÂÃ,  ÂÃ,  MESSAGEBOX 0,"Error creating screen","error"
ÂÃ,  ÂÃ,  END
ENDIF

i = getjoystickcount
messagebox w, str$(i),"test"

DO
ÂÃ,  ÂÃ,  FILLSCREEN RGB(0,0,120)
ÂÃ,  WRITETEXT 0, 0, "Press any key to close"
ÂÃ,  ÂÃ,  FLIP
UNTIL GETKEY <> "" or run = 0

CLOSESCREEN
CLOSEWINDOW w

END

sub mainwindow
select @CLASS
case @IDCLOSEWINDOW
ÂÃ,  ÂÃ,  run = 0
endselect
return
endsub



Can anyone see what I'm doing wrong.ÂÃ,  Never tried the 2D input commands before.ÂÃ,  The program I'm working on is a port from IB Standard, and everything works OK in that using the Joystick API : declare "winmm.dll",joyGetPos(id:int,n:joyinfo),int

The help file says: 'A screen must be open or DirectInput initialized manually before using this function..'

We don't have a joystick example as yet, so I've no idea how you would 'manually' initialize DirectInput ..

best wishes, :)

Graham

Tomorrow may be too late ..

Ionic Wind Support Team

Does it show up in your joysticks control panel in Windows?
Ionic Wind Support Team

GWS

Yep .. it says 'Wingman Extreme Digital 3D - OK', and it works with several games and in the IBStd version of the program I'm converting.

It's just I can't get any response from the 2D Direct commands .. I've never tried these before, so I may be doing something silly.
I assume it doesn't matter if I've 'created' or 'attached' the screen .. the latter in this caseÂÃ,  :)

Graham
Tomorrow may be too late ..

Ionic Wind Support Team

Should work.  Your AttachScreen call is wrong though,  When attaching a screen to a window you don't specify the BPP.  The last parameter is whether the directx surface is scaled to fit the client area of the window or not.  So it is either TRUE ot FALSE.

It might be possible that the version of DirectInput the commands used isn't compatible with that stick.   Have to look into it further.

Paul.
Ionic Wind Support Team

GWS

OK Paul thanks .. I'll keep experimenting ..ÂÃ,  :)

all the best,

Graham
Tomorrow may be too late ..

GWS

Oh .. forgot to mention .. there seems to be no response from 'Getkey' either ..

a$ = GETKEY
IF a$ <> "" THEN b$ = a$
WRITETEXT 0,20,"You Pressed: " + b$

I'm running DX 9.0c here ..  :)

Graham
Tomorrow may be too late ..

Ionic Wind Support Team

Try it in full screen mode and see what happens.
Ionic Wind Support Team

Ionic Wind Support Team

December 04, 2006, 02:16:22 AM #7 Last Edit: December 04, 2006, 02:19:45 AM by Paul Turley
I'm running 9.0c as well.  Try this program, it uses DirectInput without a 2D screen.  Arrow keys move the dot around and it displays the position and button presses of the first joystick.


/*
small example of how to use the 2D direct input functions in a regular window
just for those that want to try it, not really much use since
Direct Input was meant for games and GDI is too slow for most uses
but it could be applied to simple GDI game. Like tetris or something.
There are numerous ways to do this. I used KEYDOWN in the main loop.
But you could also use a timer and check for keys then for speed control
*/

'declare some functions
DECLARE extern _InitDInput(hwnd as UINT)
DECLARE extern _FreeDInput()
'and one API call
DECLARE IMPORT,InvalidateRect(hwnd:UINT,drect:POINTER,bErase:int),int
'some convenient scancodes
CONST DIK_UP =             0xC8    /* UpArrow on arrow keypad */
CONST DIK_LEFT =           0xCB    /* LeftArrow on arrow keypad */
CONST DIK_RIGHT =          0xCD    /* RightArrow on arrow keypad */
CONST DIK_DOWN =           0xD0    /* DownArrow on arrow keypad */

left = 0
top = 0
width = 0
height = 0
'play with this. Higher numbers move the block faster
speed = .1f

DEF mainwnd as WINDOW
DEF px,py as FLOAT
OPENWINDOW mainwnd,0,0,640,480,@NOAUTODRAW,0,"Direct Input Test",&handler
'initialize DirectInput and associate it with our window
_InitDInput(mainwnd.hwnd)
'get the 'real' size of our drawing surface.
GETCLIENTSIZE mainwnd,left,top,width,height
IF GetJoystickCount()
move mainwnd,0,20
PRINT mainwnd,GetJoystickCount()
move mainwnd,0,40
PRINT mainwnd,GetJoystickName()," Type = ",GetJoystickType()
ENDIF
GETCLIENTSIZE mainwnd,left,top,width,height
DO
IF KEYDOWN(DIK_UP)
IF py > 0
MovePlayer(px,py-speed)
ENDIF
ENDIF
IF KEYDOWN(DIK_DOWN)
IF py < (height-10)
MovePlayer(px,py+speed)
ENDIF
ENDIF
IF KEYDOWN(DIK_LEFT)
IF px > 0
MovePlayer(px-speed,py)
ENDIF
ENDIF
IF KEYDOWN(DIK_RIGHT)
IF px < (width-10)
MovePlayer(px+speed,py)
ENDIF
ENDIF
IF GetJoystickCount()
IF JOYDOWN(0)
MOVE mainwnd,0,100
PRINT "Button 0 pressed"
ELSE
MOVE mainwnd,0,100
PRINT "                               "
ENDIF
IF JOYDOWN(1)
MOVE mainwnd,0,120
PRINT "Button 1 pressed"
ELSE
MOVE mainwnd,0,120
PRINT "                               "
ENDIF
'show the joystick position
MOVE mainwnd,0,140
PRINT mainwnd,JOYX(),JOYY(),"                "
ENDIF
WAIT 1
UNTIL mainwnd = NULL

_FreeDInput()
END

SUB handler
SELECT @CLASS
CASE @IDCLOSEWINDOW
CLOSEWINDOW mainwnd
CASE @IDPAINT
'draw the player
RECT  mainwnd,px,py,10,10,RGB(255,0,0),RGB(255,0,0)
ENDSELECT
RETURN
ENDSUB

SUB MovePlayer(newx as float,newy as float)
DEF rc as WINRECT
rc.left = px
rc.right = px+10
rc.top = py
rc.bottom = py+10

'erase the old one by having Windows send an @IDPAINT message
'with the background set for redrawing
InvalidateRect(mainwnd.hwnd,rc,TRUE)

px = newx
py = newy

rc.left = px
rc.right = px+10
rc.top = py
rc.bottom = py+10
'invalidate the new one so Windows redraws it
InvalidateRect(mainwnd.hwnd,rc,FALSE)
RETURN
ENDSUB
Ionic Wind Support Team

GWS

Hi Paul,

The arrow keys move the dot OK, but there's no sign of the joystick.

Looks like the _InitDInput may not be working ..

I'll try fullscreen .. :)

Graham
Tomorrow may be too late ..

Ionic Wind Support Team

The arrow keys are from direct input.  That's what the KEYDOWN function does.  So we know at least the keyboard is working with it.

Ionic Wind Support Team

GWS

Checked out a new joystick controlled game - that's working OK.

Checked 'Getkey' in the test program - that's working as well as 'Keydown' ..

No sign of the joystick yet .. I'll knock up a fullscreen test next .. :)

Graham
Tomorrow may be too late ..

GWS

Nope - 'GetJoyStickCount' reports 0 in fullscreen as well ..

Graham
Tomorrow may be too late ..

GWS

Hi, aren't I a nuisance ..ÂÃ,  :)

Back to using the API ..

int r,x,y

' UDT for joystick ..
type joyinfo
ÂÃ,  ÂÃ, def Xpos:int
ÂÃ,  ÂÃ, def Ypos:int
ÂÃ,  ÂÃ, def Zpos:int
ÂÃ,  ÂÃ, def Button:int
endtype

def joy:joyinfo
declare "winmm.dll",joyGetPos(id:int,n:joyinfo),int

Do
' check joystick status ..
         r = joyGetPos(0,joy)
         x = joy.Xpos
         y = joy.Ypos
WriteText 100,200,"JS"+str$(x)+str$(y)
Until ...

This works OK giving ranges 0 - 65535 ..

So Windows and my joystcik are working .. :)

Graham

Tomorrow may be too late ..

redea30591

I know this is an old topic, just wondering if there's been any follow-up to it?  I tried the sample code and made the changes to the attached window, etc. and my system reports "0" joysticks as well for my "Cyborg Rumble Pad"  Don't really plan on doing anything fancy and could just as well use the standard API, but would rather do it the easiest way possible, rather than having to add in imports from system .dll's, use built in commands if possible.... Unfortiantly, seems that's not an option....