AutoHotkey Community

It is currently May 27th, 2012, 12:35 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: November 25th, 2011, 6:35 pm 
Offline

Joined: October 13th, 2011, 8:58 pm
Posts: 7
How can I make a script to bind 2 keyboard/2 joystick buttons into one JOYSTICK one?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2011, 7:28 pm 
Offline

Joined: December 24th, 2006, 4:36 am
Posts: 42
Just to clarify, you want to make it so that both buttons (or keys) on the keyboard will perform the same function?

In this example, 1Joy1 and 1Joy2 are PHYSICAL joystick buttons (non ppjoy). Autohotkey does not trigger "1Joy1 up::" events when buttons are released so they have to be polled at regular intervals. With keyboard hotstrings you can have events like: "w up::" "s up::" "a up::", etc...

Code:
; do your script startup stuff here
; ================================================
   1Joy1 := False
   1Joy2 := False
return
; ================================================
; end of startup stuff

; ================================================
; hotkey for button 1
; ================================================

1Joy1::
   1Joy1 := True ; track button state
   SetTimer, Poll_1Joy1, 100 ; track button release every 100ms
   if (!1Joy2) ; is the SECOND button released?
      PPJ_SetButton(1, 1) ; press the virtual button
return

Poll_1Joy1:
   1Joy1 := GetKeyState("1Joy1") ; continue to track button state
   if (!1Joy1) ; button is no longer being held down?
   {
      SetTimer, Poll_1Joy1, off ; stop tracking button release
      if (!1Joy2) ; is the SECOND button released?
         PPJ_SetButton(1, 0) ; release the virtual button
   }
return

; ================================================
; hotkey for button 2
; ================================================

1Joy2::
   1Joy2 := True ; track button state
   SetTimer, Poll_1Joy2, 100 ; track button release every 100ms
   if (!1Joy1) ; is the FIRST button released?
      PPJ_SetButton(1, 1) ; press the virtual button
return

Poll_1Joy2:
   1Joy2 := GetKeyState("1Joy2") ; continue to track button state
   if (!1Joy2) ; button is no longer being held down?
   {
      SetTimer, Poll_1Joy2, off ; stop tracking button release
      if (!1Joy1) ; is the FIRST button released?
         PPJ_SetButton(1, 0) ; release the virtual button
   }
return



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2011, 7:49 pm 
Offline

Joined: October 13th, 2011, 8:58 pm
Posts: 7
le-mec wrote:
Just to clarify, you want to make it so that both buttons (or keys) on the keyboard will perform the same function?

In this example, 1Joy1 and 1Joy2 are PHYSICAL joystick buttons (non ppjoy). Autohotkey does not trigger "1Joy1 up::" events when buttons are released so they have to be polled at regular intervals. With keyboard hotstrings you can have events like: "w up::" "s up::" "a up::", etc...

Code:
; do your script startup stuff here
; ================================================
   1Joy1 := False
   1Joy2 := False
return
; ================================================
; end of startup stuff

; ================================================
; hotkey for button 1
; ================================================

1Joy1::
   1Joy1 := True ; track button state
   SetTimer, Poll_1Joy1, 100 ; track button release every 100ms
   if (!1Joy2) ; is the SECOND button released?
      PPJ_SetButton(1, 1) ; press the virtual button
return

Poll_1Joy1:
   1Joy1 := GetKeyState("1Joy1") ; continue to track button state
   if (!1Joy1) ; button is no longer being held down?
   {
      SetTimer, Poll_1Joy1, off ; stop tracking button release
      if (!1Joy2) ; is the SECOND button released?
         PPJ_SetButton(1, 0) ; release the virtual button
   }
return

; ================================================
; hotkey for button 2
; ================================================

1Joy2::
   1Joy2 := True ; track button state
   SetTimer, Poll_1Joy2, 100 ; track button release every 100ms
   if (!1Joy1) ; is the FIRST button released?
      PPJ_SetButton(1, 1) ; press the virtual button
return

Poll_1Joy2:
   1Joy2 := GetKeyState("1Joy2") ; continue to track button state
   if (!1Joy2) ; button is no longer being held down?
   {
      SetTimer, Poll_1Joy2, off ; stop tracking button release
      if (!1Joy1) ; is the FIRST button released?
         PPJ_SetButton(1, 0) ; release the virtual button
   }
return



The thing im trying to do is to get numpad8 and numpad6 pressed at the same time from a joystick button. Either that or, joystick buttons 1 and 2 pressed at the same time from joystick button 8 for example. I tried that with a simple

Joy1::
SendInput, {numpad8 down}{numpad6 down}
Sleep 100
SendInput, {numpad8 up}{numpad6 up}
return


but problem is that it doesn't read joystick buttons, so Im trying to do the same script with PPjoy, however I have no idea how to.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2011, 8:39 pm 
Offline

Joined: December 24th, 2006, 4:36 am
Posts: 42
Notice how I do something like: "1Joy1" rather than "Joy1"

The first number is the Joy ID. It's important if you have more than one joystick adaptor connected (this includes virtual adaptors)

You can swap Joy IDs with wingmanteam's JoyID swapper

Code:
; do your script startup stuff here
; ================================================

#Persistent ; keep the script running forever
#SingleInstance force ; only allow one instance of the script to run at a time. launching the script again will reload and restart the current instance.

SplashTextOn,,, Keymasher Starting...

Process, Priority, , High
EnvGet, InstallDir, APPDATA

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

SplashTextOff

return
; ================================================
; end of startup stuff

1Joy1::
   Send, {numpad6 down}
   Send, {numpad8 down}
return


Poll_1Joy1:
   1Joy1 := GetKeyState("1Joy1") ; continue to track button state
   if (!1Joy1) ; button is no longer being held down?
   {
      SetTimer, Poll_1Joy1, off ; stop tracking button release
      Send, {numpad8 up}
      Send, {numpad6 up}
   }
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 25th, 2011, 8:41 pm 
Offline

Joined: December 24th, 2006, 4:36 am
Posts: 42
Also I don't use PPJoy to read joystick values. Use GetKeyState instead.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2011, 9:25 am 
Offline

Joined: October 13th, 2011, 8:58 pm
Posts: 7
le-mec wrote:
Notice how I do something like: "1Joy1" rather than "Joy1"

The first number is the Joy ID. It's important if you have more than one joystick adaptor connected (this includes virtual adaptors)

You can swap Joy IDs with wingmanteam's JoyID swapper

Code:
; do your script startup stuff here
; ================================================

#Persistent ; keep the script running forever
#SingleInstance force ; only allow one instance of the script to run at a time. launching the script again will reload and restart the current instance.

SplashTextOn,,, Keymasher Starting...

Process, Priority, , High
EnvGet, InstallDir, APPDATA

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

SplashTextOff

return
; ================================================
; end of startup stuff

1Joy1::
   Send, {numpad6 down}
   Send, {numpad8 down}
return


Poll_1Joy1:
   1Joy1 := GetKeyState("1Joy1") ; continue to track button state
   if (!1Joy1) ; button is no longer being held down?
   {
      SetTimer, Poll_1Joy1, off ; stop tracking button release
      Send, {numpad8 up}
      Send, {numpad6 up}
   }
return


Thanks for this, but there is a problem, the script works only once,if I try to press Joy1 a second time nothing happens.I have to click on another window then go back to my game if I want it to work again. I tried removing this "#SingleInstance force" but same thing occured - It only worked once. Any thoughts?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 26th, 2011, 9:32 am 
Offline

Joined: December 24th, 2006, 4:36 am
Posts: 42
Yeah I screwed up.

I was missing:

"SetTimer, Poll_1Joy1, 100 ; track every 100ms"

Code:
; do your script startup stuff here
; ================================================

#Persistent ; keep the script running forever
#SingleInstance force ; only allow one instance of the script to run at a time. launching the script again will reload and restart the current instance.

SplashTextOn,,, Keymasher Starting...

Process, Priority, , High
EnvGet, InstallDir, APPDATA

SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.

SplashTextOff

return
; ================================================
; end of startup stuff

1Joy1::
   Send, {numpad6 down}
   Send, {numpad8 down}
   SetTimer, Poll_1Joy1, 100 ; track every 100ms
return


Poll_1Joy1:
   1Joy1 := GetKeyState("1Joy1") ; continue to track button state
   if (!1Joy1) ; button is no longer being held down?
   {
      SetTimer, Poll_1Joy1, off ; stop tracking button release
      Send, {numpad8 up}
      Send, {numpad6 up}
   }
return


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 4th, 2011, 6:13 pm 
I"m trying to figure out how to pass Lbutton and Rbutton clicks (and holds) to PPJoy button 1 and 2 holds. I tried.

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

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

But that just hijacked the mouse buttons, and they wouldn't work at all (which made closing the script and getting my mouse buttons back fun). I modified these lines off the example earlier with the a button. Can't figure out what it needs to be. I guess maybe it did work, but I still need the mouse button click to act as a mouse click.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2011, 6:59 pm 
Quote:
I"m trying to figure out how to pass Lbutton and Rbutton clicks (and holds) to PPJoy button 1 and 2 holds. I tried.

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

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

But that just hijacked the mouse buttons, and they wouldn't work at all (which made closing the script and getting my mouse buttons back fun). I modified these lines off the example earlier with the a button. Can't figure out what it needs to be. I guess maybe it did work, but I still need the mouse button click to act as a mouse click.


Figured out part of the problem. I changed:
LButton::
MouseClick, left,,,,, D ; Left click Down
PPJ_SetButton(1,1) ; Set Button 1 True
Keywait, LButton ; Wait for button to be released
MouseCLick, left,,,,, U ; Left Click Up
PPJ_SetButton(1,0) ; Set Button 1 False
Return

Which works mostly for my application. I'm having problems with a non-ahk part of my setup now. When I click and hold the physical mouse button, it works as it should, but when I use another program to send a held mouse click, it behaves as if it only clicks and releases.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 4th, 2011, 10:09 pm 
Offline

Joined: December 24th, 2006, 4:36 am
Posts: 42
Code:
; prefixing with a "~" tilde allows the mousebutton to pass thru
~LButton::
   PPJ_SetButton(1,1) ; Set Button 1 True
Return

; I use "LButton up" instead of the keywait function because keywait pauses the whole script.
~LButton up::
   PPJ_SetButton(1,0) ; Set Button 1 False
Return

; prefixing with a "~" tilde allows the mousebutton to pass thru
~RButton::
   PPJ_SetButton(2,1) ; Set Button 2 True
Return

; I use "RButton up" instead of the keywait function because keywait pauses the whole script.
~RButton up::
   PPJ_SetButton(2,0) ; Set Button 2 False
Return


PS: try to use the phpBB "code" tags to make your code more readable
PPS: also, indent between your goto-labels and your return statements so you don't get lost


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: PPJoy library
PostPosted: May 24th, 2012, 8:48 pm 
Offline

Joined: December 24th, 2006, 4:36 am
Posts: 42
Recently added a range-check function so that invalid buttons or axes called are simply discarded.

Source code is included.

http://www.mediafire.com/?p6i7i5857e23sb6


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 41 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, maul.esel and 7 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group