Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

PPJoy library


  • Please log in to reply
69 replies to this topic
ninjabob7
  • Members
  • 4 posts
  • Last active: Jul 11 2011 12:13 AM
  • Joined: 02 Jan 2010
I had nothing to do this Saturday, so I wrote this library which allows you to control a PPJoy virtual joystick from within AHK. I can't guarantee if it's any good, as I have almost no experience with C and not much with AHK.

PPJoy.zip

This zip file contains a DLL which is basically ripped off from this sample code: http://ppjoy.bosssta...rtual/IOCTL.htm
along with the AHK library that calls it and the source. You'll need to install PPJoy separately and set up a virtual joystick with the default settings. Then just put PPJoy.dll with AutoHotkey.exe, and PPJ.ahk in the lib folder.

Just look at the AHK source to see what the functions are. The button values are either 0 (up) or 1 (down) and the axes are from 0 to 100.

This is just a rough draft, so let me know if I should add additional functions.

Snowie0wl
  • Members
  • 11 posts
  • Last active: Nov 18 2013 09:07 AM
  • Joined: 12 Jan 2010
This looks pretty neat. I'll be trying it out now to see if I can get the throttle control I'm after. Thanks for posting it.

trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
[color=green]hModule := 0[/color]

PPJ_Init()
{
   [color=red]global hModule[/color]
	hModule := DllCall("LoadLibrary", "str", "PPJoy.dll")
	Result := DllCall("PPJoy\Initialize")
}

PPJ_Term()
{
   [color=red]global hModule[/color]
	DllCall("PPJoy\Close")
	DllCall("FreeLibrary", "UInt", hModule)
}

Green - Not needed
Red - Needed

Seeing as how PPJ_Init() sets hModule, there is no need to declare it out of the function (This also does not make it a global variable, like it does in C/many other languages). To make a variable global, use the global command.
Religion is false. >_>

le-mec
  • Members
  • 51 posts
  • Last active: Dec 15 2011 02:30 AM
  • Joined: 24 Dec 2006
YESSS!!!!

Thanks so much ninjabob, I had been waiting for a PPJoy DLL for aeons! You are a king among men.

EDIT: It works great - now I can finally pass information from my wacom tablet via AHKHID to GlovePIE!

passer
  • Guests
  • Last active:
  • Joined: --
hi ninjabob,

can you help me with it? i have ppjoy 0.8.4.5, created virtual joystick
what is next step? i ran "user dll joystick" and browsed for your ppj.dll
i get "error 127 getting InitDLL() entry" message
as i dont have any experience with ppjoy/programming maybe i'm doing something very wrong.
short tutorial would be appreciated :)

thank you

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
its not tested, but i think it should work this way (avoid globals):

;PPJoy library
;by Ninja Bob
;January 2, 2010


PPJ_Init()
{
	hModule := DllCall("LoadLibrary", "str", "PPJoy.dll")
	PPJ_m( "hm", hModule, "SET" )
	Result := DllCall("PPJoy\Initialize")
}

PPJ_Term()
{
	DllCall("PPJoy\Close")
	DllCall("FreeLibrary", "UInt", PPJ_m( "hm" ) )
}

PPJ_SetButton(button, state)
{
	DllCall("PPJoy\SetButton", "char", button - 1, "char", state)
	DllCall("PPJoy\Update")

}

PPJ_SetAxis(axis, value)
{
	DllCall("PPJoy\SetAxisPercent", "char", axis - 1, "char", value)
	DllCall("PPJoy\Update")
}

PPJ_GetButton(button)
{
	Return DllCall("PPJoy\GetButton", "char", button - 1)
}

PPJ_GetAxis(axis)
{
	Return DllCall("PPJoy\GetAxisPercent", "char", axis - 1)
}

PPJ_ResetButtons()
{
	DllCall("PPJoy\ResetButtons")
	DllCall("PPJoy\Update")
}

PPJ_ResetAxes()
{
	DllCall("PPJoy\ResetAxes")
	DllCall("PPJoy\Update")
}

PPJ_m(n,v="",m="GET")
{
	static
	if ( m="SET" )
	{
		_%n% := v
	}
	Else
	{
		return _%n%
	}
}

greets
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

le-mec
  • Members
  • 51 posts
  • Last active: Dec 15 2011 02:30 AM
  • Joined: 24 Dec 2006
By default, this DLL only allows access to the FIRST PPJoy Virtual Joystick.
If you want to control a different virtual joystick, then:

(first make a backup and) open your PPJoy.dll file in a hexidecimal editor (XVI32 is a good one)

Go to address $140E

You'll probably see something like: PPJoyIOCTL1

That's a reference to the FIRST PPJoy device.
To control the 2nd virtual joystick, simply change that digit to: PPJoyIOCTL2
To control the 5th virtual joystick, simply change that digit to: PPJoyIOCTL5

etc. etc. capiche?

Also, here is a cross-reference for those of you who happen to be using PPJoy with GlovePIE (since the axis names vary)

sqlninja01
  • Members
  • 54 posts
  • Last active: Oct 17 2015 12:41 PM
  • Joined: 21 Oct 2009
Can you post a quick example of how one would let's say emulate a axis moving all the way left, when keyboard key "A" is pressed?


I've tried the following without success:
#include PPJ.ahk

PPJ_Init()

~a::
PPJ_SetAxis(X Axis, 100)
Return
Thanks in advance.[/code]

PoP
  • Members
  • 1 posts
  • Last active: Jan 25 2012 12:31 PM
  • Joined: 18 Apr 2010
I think PPJ_SetAxis(0, 100) will work since the X axis is mapped to PPJoy Analog 0 input.

Cabanas
  • Guests
  • Last active:
  • Joined: --
I am having difficulties too about using ahk with ppjoy, mainly with axis. Can someone post a tutorial, step by step, for the noobs explaining how to do this?

Cabanas
  • Guests
  • Last active:
  • Joined: --
Anyone would like to help us?

Mr Elmo
  • Members
  • 18 posts
  • Last active: Jun 18 2010 05:46 PM
  • Joined: 25 Oct 2006
Took me a while to figure out that calling PPJ_SetAxis(0,Xvar) was trying to handle axis -1, because of the decrementer in the library.

So here's an example code that sets the joystick info to your mouse's screen position, and maps 'a' to button1.

Thank you ninjabob!

OnExit, ExitHandler
CoordMode, Mouse, Screen

PPJ_Init()	; Grab the Joystick

Loop {
	MouseGetPos, MouseX, MouseY
	
	; Values must be within 0-100 range
		YVal := 100-Round(100*(A_ScreenHeight-MouseY)/A_ScreenHeight)
		XVal := 100-Round(100*(A_ScreenWidth-MouseX)/A_ScreenWidth)
	
	PPJ_SetAxis(2, Yval) ;Axis 2 is the Y axis
	PPJ_SetAxis(1, Xval) ;Axis 1 is the X axis
}

Return

a::
	PPJ_SetButton(1,1)	; Set Button 1 True
	Keywait, a			; Wait for button to be released
	PPJ_SetButton(1,0)	; Set Button 1 False
Return

ExitHandler:
	PPJ_Term()	; Release the Joystick
ExitApp

%MemorablePhrase%

sqlninja01
  • Members
  • 54 posts
  • Last active: Oct 17 2015 12:41 PM
  • Joined: 21 Oct 2009

I think PPJ_SetAxis(0, 100) will work since the X axis is mapped to PPJoy Analog 0 input.


This does work. However if the joystick is being moved in any way, the Script does not work. Any ideas to make the script take absolute control of the joystick?

stanley550
  • Members
  • 2 posts
  • Last active: May 10 2010 11:08 PM
  • Joined: 10 May 2010
Sorry to steal the thread for a couple of posts, but how can I get data from Wacom into GlovePie?

I'm trying to get Pen mapping while using my fingers on Bamboo Pen And Touch tablet.

Thank you.

victoras_h
  • Guests
  • Last active:
  • Joined: --
Hello,

I also would like to ask for a short step by step noob guide.

I'm trying to set up a virtual joystick, to be controlled with the keyboard. I only need 2 axes which stay on neutral and two keys defined for each for max and min values. Also I would need a third axes for a sort of throttle control: it should stay on the minimum level and increase it by 20% increments with a few keys, like 1 = 20%, 2 = 40%, etc.

Is this possible?