Jump to content

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

Gamepad script (autohold)


  • Please log in to reply
15 replies to this topic
darthobnoxious2
  • Members
  • 8 posts
  • Last active: Nov 07 2011 05:52 AM
  • Joined: 06 Nov 2011
I've been having a little bit of a problem with a program. basically, I need to continuously hold down a game-pad button. I saw on a forum that this program can be used to do this, but I'm hopeless with scripts, and I've been trying to wrap my head around it for the last half hour, with no luck.

I have been able to figure out, though, that the button I need to be held down is registered as Joy4 for this program. Thanks in advance if anyone can help me out.

jpjazzy
  • Members
  • 800 posts
  • Last active: Feb 05 2013 02:19 AM
  • Joined: 16 Feb 2010
Try this:

$Joy4::
SendInput, {Joy4}
Sleep 500 ; 500 ms before starting the loop.
While GetKeyState("Joy4","p"){
   Sleep 20 ; 20 ms between each button push 
   SendInput, {Joy4}
}
return


darthobnoxious2
  • Members
  • 8 posts
  • Last active: Nov 07 2011 05:52 AM
  • Joined: 06 Nov 2011
012: SendMode,Input
013: SetWorkingDir,%A_ScriptDir%
015: Return (6.32)
016: SendInput,{Joy4}
017: Sleep,500 (0.50)
018: While,GetKeyState("Joy4","p")
019: Sleep,20 (0.02)
020: SendInput,{Joy4}
021: }
019: Sleep,20 (0.01)
020: SendInput,{Joy4}
021: }
019: Sleep,20 (0.02)
020: SendInput,{Joy4}
021: }
019: Sleep,20 (0.01)
020: SendInput,{Joy4}
021: }
019: Sleep,20 (0.02)
020: SendInput,{Joy4}
021: }
022: Return (61.37)

That's what was in the autohotkey menu.

I tried it both with, and without, the text in red, and neither worked. And yes, I did make sure to reload the script after saving the changes.

Thanks for trying.

Basically, I have an audio recording program that lets me record from multiple different sources. I need a way to start them at the same time, and, I can program them to record while the gamepad button is being held. But, it has to be held down, which is unfortunate. That's basically what I'm trying to do.

jpjazzy
  • Members
  • 800 posts
  • Last active: Feb 05 2013 02:19 AM
  • Joined: 16 Feb 2010
Well then try {Joy4 Down} (push the key down and hold it until the up is specified or you let it up) and {Joy4 Up}?

darthobnoxious2
  • Members
  • 8 posts
  • Last active: Nov 07 2011 05:52 AM
  • Joined: 06 Nov 2011
Apparently, according to the help manual...
Limitations: 1) "Up" does not work with joystick buttons

I tryed all the configurations of adding "Down" after Joy4 that I could think of, and none of them worked.
Sorry, unless I screwed something up, it doesn't hold down the key.

Thanks for trying.

jpjazzy
  • Members
  • 800 posts
  • Last active: Feb 05 2013 02:19 AM
  • Joined: 16 Feb 2010
Since I don't have a controller to test on the joystick pieces, it makes this area of scripting a little hard for me. Sorry I couldn't help you more, but perhaps someone else can.

darthobnoxious2
  • Members
  • 8 posts
  • Last active: Nov 07 2011 05:52 AM
  • Joined: 06 Nov 2011
As I said, thanks for trying. You know this stuff better than me XD. I just can't seem to wrap my mine around it. Unless you know of a way to click at several different places on screen at the same time...

jpjazzy
  • Members
  • 800 posts
  • Last active: Feb 05 2013 02:19 AM
  • Joined: 16 Feb 2010
ControlClickwith the down command should do it.

darthobnoxious2
  • Members
  • 8 posts
  • Last active: Nov 07 2011 05:52 AM
  • Joined: 06 Nov 2011
Only problem: I really don't understand this program and the scripts at all. It's just really difficult for me. plus, from what I read, it looks like it would be difficult to have them click at the exact same time. If they don't there will be an annoying Desync.

jpjazzy
  • Members
  • 800 posts
  • Last active: Feb 05 2013 02:19 AM
  • Joined: 16 Feb 2010
First thing to note, all parameters in a command that are between [] brackets are OPTIONAL meaning you can just put a comma to go to the next parameter (unless it is a function and not a command) and skip that piece.

It really isn't all that hard if you want to learn. Do you know what a graph is? The controls are X and Y based just like a graph for the positioning, except the Y variable goes UP as you move the mouse lower. Unless otherwise noted all the commands are relative to a window meaning you consider each window kind of like it's own graph. You can change that to CoordMode, << Piece to change >>, Screen and then the graph covers your entire screen rather than a window. If you read the basic documentation or look at windows spy you can see this. For the other parameters in each command they are right there.

WinTitle - The title of the window... Pretty self explanatory.

WinText - Usually this is not used for the most part but it contains text from the window.

WhichButton - Again... Pretty self explanatory. What button on the mouse to click?

ClickCount - How many clicks to send.

Options - Just specify the option(s) you want from the listed options.

If you don't want to make an attempt because you are scared, that's fine, but the best way to learn is too just dive in and do some experimentation. Don't be scared, AHK won't bite...

darthobnoxious2
  • Members
  • 8 posts
  • Last active: Nov 07 2011 05:52 AM
  • Joined: 06 Nov 2011
You're talking to someone who has never done any bit of coding... ever. plus, another problem is, I have a bad habit of moving windows around, even when I shouldn't. Sorry, I've tried my best to understand this stuff, but I can't even grasp the basics.

nimda
  • Members
  • 4368 posts
  • Last active: Jan 15 2014 02:47 PM
  • Joined: 26 Dec 2010
Have you seen the tutorial at the top of the Ask for Help forum? How about <!-- m -->http://d.ahk4.me/Tutorial<!-- m --> ?

jpjazzy
  • Members
  • 800 posts
  • Last active: Feb 05 2013 02:19 AM
  • Joined: 16 Feb 2010
Nimda is right. If you want to learn you need to look at the tutorials and manual, then just make a test script and start playing with things. When I started I had near 0 experience too, however AutoHotkey is designed to be a user-friendly language (if it can even be called a language I guess). It's one of the most forgiving ways of developing out there, so if you want to learn basic concepts, I suggest starting here.

As I mentioned earlier EACH WINDOW is it's own graph. We call this 'relative mode' because it is relative to the active window. Look at these pictures:

<!-- m -->http://vvcap.net/db/...CFR6QSUeqXV.htp<!-- m -->
&&
<!-- m -->http://vvcap.net/db/...5guxQTUSwRi.htp<!-- m -->

See how the relative coordinate remains in the same place on the window even when you move it? This is why relative is the default setting on AutoHotkey.

If you aren't interested in learning, you don't have too, but if you really want too, you can with 0 experience. That's the beautiful thing about AutoHotkey.

If you take the time to learn, I am sure you won't regret it. Being able to design a good looking and functioning program/script in minutes is a valuable skill. Good luck.

darthobnoxious2
  • Members
  • 8 posts
  • Last active: Nov 07 2011 05:52 AM
  • Joined: 06 Nov 2011
Okay, I've been trying to create a code myself. I actually think I've gotten it pretty close, but there is a little I want help on...

So, is there a way for me to have the scrip only apply to a certain window?

Currently, my scrip (and it works, BTW) is

Z::MouseClick, Left , 197, 111, 1, 0, 

x::MouseClick, Left , 583, 110, 1, 0,

The only two things more I want to do, is have them always apply to "VRS Recording System" (That's what window spy says it's called) and, to press both the Z and X keys simultaneously, at the press of say, the C key. Other than that, I have it down to what I need it to be. It's late, I need to head off to bed now, but it would be nice If someone here woud be able to finish my script for me. If not, I could probably figure out how (given enough time) but it's already confusing enough for me XD[/code]

jpjazzy
  • Members
  • 800 posts
  • Last active: Feb 05 2013 02:19 AM
  • Joined: 16 Feb 2010
At least you are making an attempt. Always nice to see. 8) Every good scripter starts somewhere.

Note, the ControlClick only applies to certain windows if you make that an option AND the windows don't need to be active for it to work. It will click on the window without showing as active if you don't want it to. Take a look at this:

c:: ; Uses the c key to do both of your clicks
ControlClick, X197 Y111, [color=red]<<Title of the window from the Z click>>[/color] ,,,, NA  ; Clicks the z location WITHOUT activating the window
ControlClick, X583 Y110, [color=red]<<Title of the window from the x click>>[/color] ,,,, NA  ; Clicks the x location WITHOUT activating the window
return

If you want more then one command in a hotkey, just move it to the next line and end the key with a return (just like the return there is at the bottom).

Note: Some windows do not accept ControlClicks, so if that is the case you can just rearrange this with your MouseClicks and the WinActivate command.