Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

13 minutes ago, JoeViking245 said:

@drw4013 @skizzosjt  If Windows sees your controller, you shouldn't have any issues with AHK detecting it.  With it plugged in and on, press Win + R on your keyboard, type "joy.cpl" (without quotes) and press enter.  

image.png.58e7a598faaedb2961a39c53a334d9c9.png

 

Here's a little ditty from the AHK Docs that talks about remapping controllers.  Remapping a Joystick to Keyboard or Mouse | AutoHotkey

Note that remapping via AHK is one-way.  That is, you can setup a hotkey to detect a controller button press (joy stick, d-pad and even z-trigger) and remap that to send a keyboard input (or do some other task).  But, via AHK you can't setup a hotkey that will send a controller button-press.

; Good
1Joy1::
MsgBox, you pressed button 1 on your controller

; Not good (pressing Alt+a will not "press" button 1
!a::
Send, 1joy1

Test the "Good" one outside of LaunchBox like you did the other.  You don't need XInput.dll.  It should just work.  If you read the Doc from the link above, you'll notice their examples don't use the preceding 1 in Joy1.  That 1st "1" is denoting controller #1.  If you have more that 1 controller plugged in and it doesn't work, you may be holding controller #2.  Myself, I only have 1 controller to test with.

Also note that button numbering may vary between emulators.  Example, the Start button may be "7" in one emulator but "8" in another.

Now, if you're trying to get your script to work in a Windows game, Steam or some variant there-of, that could be a whole 'nother issue.  And not a good one, I might add.  They can usually be a right PITA.

 

But back to your original issue... "insert coin doesn't work for some games in MAME/FBNeo".  If MAME (I'm assuming stand-alone MAME) is accepting your other controller inputs, it surely will accept one for Coin Input.  But if it (coin input) works in some games and not others, chances are you have a cfg or ini file associated with that (those) game(s) that's overriding the coin input.  The 'fix' is to get it setup properly in MAME.  Right-Shift is a very odd coin input for MAME.  Also SendKey to MAME can at times be hit-or-miss.  If you're intent on 'fixing' it with an AHK script, you will need to use the one that has the sleep timer ("Sleep, 50") in it between key_down and key_up.  Or it definitely will never work.

image.png

I used your first test script by itself outside of LB, and get nothing.  I always test the controller in Game Controllers -> Properties as well.

I previously tested a simple

1Joy1:: send a

script and it didn't work, both as above and without the "1" before "Joy1".  Seems like the Xbox One controller just isn't picked up by AHK in Win10 by default.

Edited by drw4013
Link to comment
Share on other sites

6 minutes ago, drw4013 said:

I previously tested a simple script

When testing, try testing with something that will give you a visual response. 

1Joy1::MsgBox, you pressed button 1 on your controller

A message box will always show up (when it works ;)), but depending on what window has focus, "send a" may not always give a response.  I've done that too many times where the window wasn't focused and I'm screaming 'why isn't this working'. lol

 

Windows 10 is fine, but I can't attest to an Xbox One controller as I don't have 1.  But at the same time, it's xinput. And xinput by any other name is still xinput.  Those things don't have a switch or some sort of button sequence press that switches it to dinput.  Does it?  That would surely mess things up.

  • Like 1
Link to comment
Share on other sites

33 minutes ago, JoeViking245 said:

When testing, try testing with something that will give you a visual response. 

1Joy1::MsgBox, you pressed button 1 on your controller

A message box will always show up (when it works ;)), but depending on what window has focus, "send a" may not always give a response.  I've done that too many times where the window wasn't focused and I'm screaming 'why isn't this working'. lol

 

Windows 10 is fine, but I can't attest to an Xbox One controller as I don't have 1.  But at the same time, it's xinput. And xinput by any other name is still xinput.  Those things don't have a switch or some sort of button sequence press that switches it to dinput.  Does it?  That would surely mess things up.

I did try that as well. So this works:

Esc::
MsgBox, It Works!

but these don't:

1Joy1::
MsgBox, It Works!
Joy1::
MsgBox, It Works!

because AHK isn't reading the input.

Link to comment
Share on other sites

Found a good reference here: https://stackoverflow.com/questions/66219307/detecting-joystick-buttons

"Looks like its due to AutoHotkey using an old API to detect the keys, at least with windows 10, reference. It does detect them if an AutoHotkey window is active, like when you right click on the AutoHotkey icon and select 'Open'."

That is exactly what happens with my simple test script.  If the AHK window is open, it detects controller presses. And the author went on to use XInput like I am trying to do. When I try his example, though, AHK doesn't even open in the tray.

Edited by drw4013
Link to comment
Share on other sites

2 hours ago, drw4013 said:

That is exactly what happens with my simple test script.  If the AHK window is open, it detects controller presses.

When you say the AHK window, are you talking about the AutoHotkey Help window?

image.thumb.png.57a112c498a41836878e40d1a889b6da.png

That's just weird. It must be an Xbox One controller issue then.  Is that wired or wireless?  If wireless, is it an Xbox brand wireless receiver or a 3rd party one?

I ask because mine is just a regular wireless Xbox controller with an Xbox (not 3rd party) receiver and I'm not having those issues.  And using Windows 10.  I have nothing AutoHotkey running, though I do have AHK installed.  But it doesn't run in the background at all.  Just adds right-click options when you select a .ahk file in Windows explorer.

I can double click my joystick test script "test.ahk" file and it will execute, and everything works.  It also works without issue if I right-click test.ahk and select "Run Script".  Dragging test.ahk onto "AutoHotkey.exe" works as well.  I also tested from the Windows command prompt with "AutoHotkey.exe test.ahk" and that worked too.

How are you executing your test script? When you start it, is it showing in the taskbar?   image.png.047a26d49165ba013758316d73518a75.png

 

Link to comment
Share on other sites

4 minutes ago, JoeViking245 said:

When you say the AHK window, are you talking about the AutoHotkey Help window?

image.thumb.png.57a112c498a41836878e40d1a889b6da.png

That's just weird. It must be an Xbox One controller issue then.  Is that wired or wireless?  If wireless, is it an Xbox brand wireless receiver or a 3rd party one?

I ask because mine is just a regular wireless Xbox controller with an Xbox (not 3rd party) receiver and I'm not having those issues.  And using Windows 10.  I have nothing AutoHotkey running, though I do have AHK installed.  But it doesn't run in the background at all.  Just adds right-click options when you select a .ahk file in Windows explorer.

I can double click my joystick test script "test.ahk" file and it will execute, and everything works.  It also works without issue if I right-click test.ahk and select "Run Script".  Dragging test.ahk onto "AutoHotkey.exe" works as well.  I also tested from the Windows command prompt with "AutoHotkey.exe test.ahk" and that worked too.

How are you executing your test script? When you start it, is it showing in the taskbar?   image.png.047a26d49165ba013758316d73518a75.png

 

It's exactly as that author from the previous page describes it.  If I open the AHK window by right clicking the taskbar icon and choosing "open", it shows the window with the keylogger.  That is the only way it picks up the Xbox One controller presses.

I have official MS controllers and I've tried with several of them. I'm not the only one reporting this, but it may be specific to the Xbox One controller.

Link to comment
Share on other sites

3 hours ago, drw4013 said:

Found a good reference here: https://stackoverflow.com/questions/66219307/detecting-joystick-buttons

"Looks like its due to AutoHotkey using an old API to detect the keys, at least with windows 10, reference. It does detect them if an AutoHotkey window is active, like when you right click on the AutoHotkey icon and select 'Open'."

That is exactly what happens with my simple test script.  If the AHK window is open, it detects controller presses. And the author went on to use XInput like I am trying to do. When I try his example, though, AHK doesn't even open in the tray.

I think we're on the same page. That user, evilC, is the author of UCR and seems to be a knowledgeable authority on these topics.

I did like JoeViking's idea we should test with a MsgBox, I don't think I tried that. I always was trying to map for example the "A" button aka "button 0" (usually it's 0, some programs might start at 1 instead of 0) to output a keyboard key like "f". I didn't ever succeed doing this. And I also agree with Joe that there is no way AHK to output an xinput button press. That is how to got turned on to programs like virtualcontroller

 

 

3 hours ago, drw4013 said:

because AHK isn't reading the input.

I agree on that! I never went through these troubleshooting steps detailed in the AHK docs. Take a look at this here: https://www.autohotkey.com/docs/KeyList.htm#SpecialKeys

I was aware of that detailed page JoeViking shared, but I didn't have success implementing those methods

So I shared that link because I figured I could find out if AHK was detecting a button press at all this way.....and it doesn't see squat from any of my xinput controllers. There is one exception, I noticed the large Xbox "X" logo button at the top of these controllers (to turn them on/off and bring up home screens and the like) that would always come up "not found". Otherwise it did not detect a single face button, trigger, or joystick whether it was joystick position or clicking them down.

 

I tried all those huge libraries that were using commands like GetKeyState, anything and everything I've attempted has came up as a failure. I too was not capable to get a MsgBox or anything to run via AHK via an xinput button press on any of my xinput controllers.

 

I appreciate your advice and tips here @JoeViking245, but I've got to side with @drw4013, I think this whole xinput and AHK being capable of working together has been broken for X time....either both DRW and I are on the wrong path together or AHK just isn't a feasible tool to use to remap xinput right now....in my humble opinion.

 

I am on Windows 10, for what that is worth. And tried with Wired Xbox 360 (OEM Microsoft), Wireless Xbox One (OEM Microsoft and third party PowerA), and Wireless Xbox "Core" (Xbox Series X) controllers. All produced the same disappointing results. lastly here is a snip of the AHK key history detailing what I was talking about with no buttons detected. I hit the "LButton" left mouse click to go into the script in notepad, click on the Xbox controller "X logo" button once, and then hit every single key, trigger, and joystick twice in that 16.19 secs, and then hit the "X logo" button again. As you can see absolutely nothing was detected in between those "X logo" button hits. The LButton and F5 afterwards was to get to the key history page and update it to see the list. I repeated this test again today, also tried hitting the controller buttons with the AHK open window as the active window.....makes no difference in my case, nothing was detected besides the "X logo" button.

 

image.thumb.png.4e9d39e10116453e3856ea0565df9457.png

 

 

 

Jesus christ.....after I write that dissertation length post I finally got something to work! But still not in a practical way. That stackoverflow page you linked to (https://stackoverflow.com/questions/66219307/detecting-joystick-buttons) worked if I HELD THE "A" BUTTON DOWN WHILE CLICKING ONTO THE SCRIPT TO RUN IT! I altered it a bit to see if it would in fact output something practical like a keyboard key and it did! This allowed me to run the script and have enough time to bring up notepad and send some keys. The commented out lines are fine to include as well and sent back the right button number of 4096

#Include Xinput.ahk

Loop
{

SetTimer, checkForJoy1, 100


checkForJoy1:
XInput_Init()
state := Xinput_GetState(0)
if(state) {
    a_pressed := state.wButtons & 4096
    if(a_pressed) {
        ;Msgbox, Does this work [%a_pressed%]
	;Sleep, 2000	
	Send {k down}
	Sleep, 50
	Send {k up}
    }

}

}

Return

 

So perhaps there is some way to make this work better. It seems this users script just instantly exits otherwise.  I'm missing something here from an AHK standpoint....this script looks like it should keep checking for if the A button is pressed every 100ms until I explicitly terminate the script. If I put a loop in I can keep it running, but get an occasional error about the Return being out of the braces if I hold the A button down for a long time. This is super easy to send too many outputs as is. Meaning this would be great for some rapid autofire kinda option, but otherwise needs a different approach so you do not send like 4 keys with 1 button press. So.....perhaps there is some messed up convoluted way to get all this shit to work but wtf who wants to go through all this?! I could have set this up with GlovePIE or UCR in less than a minute!

 

image.thumb.png.927f4c888e10225db1bf4212aeaa916f.png

All those K's are from my Xbox One controller! I didn't need any specific AHK window open to make those button presses be seen by AHK or send the k key!

 

I don't grasp why this exits immediately (seeming immediately, if the MsgBoxes I added were not there), nor why it produces two MsgBox's here.....its like there is a "Loop, 2" line somewhere. This is how the script seems to behave by default, goes through the check and exits without any user intervention. You click OK on the "front" MsgBox (2nd one to pop up) it keeps popping back up....You gotta click on the the 1st MsgBox, then the 2nd to get the script to terminate. Hoping someone can give me a lesson on what I am missing here!  Maybe there is something going on in the included Xinput.ahk file

image.thumb.png.4d7db5d9ffc455fa66e2ba2e31c4fe6f.png

 

EDIT:

So I figured that out...maybe....I put a "#Persistent"  line in this script and that seems to get it to work in a practical fashion without a loop! I'm not sure if this is the "correct" way to deal with it though, I'm still really green to AHK so there might be a better approach

Edited by skizzosjt
Link to comment
Share on other sites

wow....fuck me......this.....works! 🎉 There's no restriction with needing the AHK tray icon window open to read the controllers input! You also need the Xinput.ahk library for this to work of course! I'm still not 100% convinced this is going to be better than existing methods using other various remapping programs, but this is a HUGE hurdle that both of you have helped out with! Here is me testing with adding in additional buttons. all 4 face buttons work here, A, B, X, and Y. The values are hexidecimal in Xinput.ahk so needed to be converted into decimal format apparently in the main script. I encourage others to play around with this and come back with their experience! After I kid you not, months of random intervals of investigating this.....this is the first time I've gotten anything even remotely useful working! Thanks so much @JoeViking245 and @drw4013 👏😁 for coming along on what feels like a crazy roller coaster of info pulling us in different directions!

 

#Include Xinput.ahk

#Persistent

SetTimer, checkForJoy1, 10


checkForJoy1:

;********
;A BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 a_pressed := state.wButtons & 4096
   	 if(a_pressed)
		 {
       		 ;Msgbox, Does this work [%a_pressed%]
		 ;Sleep, 2000	
		 Send {k down}
		 Sleep, 50
		 Send {k up}
   		 }

;********
;B BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 b_pressed := state.wButtons & 8192
   	 if(b_pressed)
		 {
       		 ;Msgbox, Does this work [%b_pressed%]
		 ;Sleep, 2000	
		 Send {p down}
		 Sleep, 50
		 Send {p up}
   		 }


;********
;X BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 x_pressed := state.wButtons & 16384
   	 if(x_pressed)
		 {
       		 ;Msgbox, Does this work [%x_pressed%]
		 ;Sleep, 2000	
		 Send {d down}
		 Sleep, 50
		 Send {d up}
   		 }

;********
;Y BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 y_pressed := state.wButtons & 32768
   	 if(y_pressed)
		 {
       		 ;Msgbox, Does this work [%y_pressed%]
		 ;Sleep, 2000	
		 Send {e down}
		 Sleep, 50
		 Send {e up}
   		 }



Return

	}
	}
	}
	}
	



; 4096 = A button
; 8192 = B button
; 16384 = X button
; 32768 = Y button  

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, skizzosjt said:

Here is me testing with adding in additional buttons.

And here is me helping with a little code clean-up. ;) 

#Include Xinput.ahk
#Persistent

SetKeyDelay, 0, 50          ;eliminates need for send {key Down} sleep 50 send {key Up}
SetTimer, checkForJoy1, 10

checkForJoy1:

XInput_Init()
state := Xinput_GetState(0)
if(state) 
{
   a_pressed := state.wButtons & 4096   ; 4096 = A button
   b_pressed := state.wButtons & 8192   ; 8192 = B button
   x_pressed := state.wButtons & 16384  ; 16384 = X button
   y_pressed := state.wButtons & 32768  ; 32768 = Y button

   if(a_pressed)
      Send, k

   if(b_pressed)
      Send, p

   if(x_pressed)
      Send, d
   
   if(y_pressed)
     Send, e

   Sleep, 100   ;helps reduce fast repeat. Increase or decrease as necessary
}

Start the script, open Notepad, press buttons.

  • Thanks 1
Link to comment
Share on other sites

28 minutes ago, drw4013 said:

Very promising! Will need to test on Tuesday as I'm heading out for the holiday weekend.  Could you configure the back/select and start buttons? Ideally even the Guide button?

I don't see anything for the guide button in the library, so that may not be possible. To make sure we're on the same page, this is the same button to power on/off the wireless controllers? The rest is already done though! :)

So far, I'm having luck here! I got all buttons working, A, B, X, Y, Left Shoulder, Right Shoulder, Back, Start, Left Joystick Click and Right Joystick Click.

Having a tough time figuring out wtf is going on with the joystick axis though. I got it to...."work".....but it's not exactly doing what I want it to. Still trying to figure out what the script is doing here with the axis and what the values are when it's moved to different positions. So I think the joysticks axis is the last bit of this puzzle! Here's what I got playing around tonight. I'll have to come back at this after letting it stew in the old noggin' for a bit. Perhaps someone else with more AHK experience will dissect this and give me a good lesson! *Beware, after seeing Joes cleaned up script just now, mine looks like a nightmare! 🤣 Also please keep in mind this is just playing around troubleshooting work in progress! I'm well aware all these outputs make zero practical sense, I just needed to see something different happen so I could keep track of what's working as I go about this

#Include Xinput.ahk
#Persistent
#SingleInstance, Force

SetTimer, checkForJoy1, 10


checkForJoy1:

;********
;A BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 a_pressed := state.wButtons & 4096
   	 if(a_pressed)
		 {
       		 ;Msgbox, Does this work [%a_pressed%]
		 ;Sleep, 2000	
		  Send {k down}
		  Sleep, 50
		  Send {k up}
   		 }

;********
;B BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 b_pressed := state.wButtons & 8192
   	 if(b_pressed)
		 {
       		 ;Msgbox, Does this work [%b_pressed%]
		 ;Sleep, 2000	
		  Send {p down}
		  Sleep, 50
		  Send {p up}
   		 }


;********
;X BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 x_pressed := state.wButtons & 16384
   	 if(x_pressed)
		 {
       		 ;Msgbox, Does this work [%x_pressed%]
		 ;Sleep, 2000	
		  Send {d down}
		  Sleep, 50
		  Send {d up}
   		 }

;********
;Y BUTTON
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 y_pressed := state.wButtons & 32768
   	 if(y_pressed)
		 {
       		 ;Msgbox, Does this work [%y_pressed%]
		 ;Sleep, 2000	
		  Send {e down}
		  Sleep, 50
		  Send {e up}
   		 }

;********
;D-PAD UP
;********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 dpadUP_pressed := state.wButtons & 1
   	 if(dpadUP_pressed)
		 {
       		 ;Msgbox, Does this work [%dpadUP_pressed%]
		 ;Sleep, 2000	
		  Send {Up down}
		  Sleep, 50
		  Send {Up up}
   		 }

;**********
;D-PAD DOWN
;**********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 dpadDOWN_pressed := state.wButtons & 2
   	 if(dpadDOWN_pressed)
		 {
       		 ;Msgbox, Does this work [%dpadDOWN_pressed%]
		 ;Sleep, 2000	
		  Send {Down down}
		  Sleep, 50
		  Send {Down up}
   		 }

;**********
;D-PAD LEFT
;**********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 dpadLEFT_pressed := state.wButtons & 4
   	 if(dpadLEFT_pressed)
		 {
       		 ;Msgbox, Does this work [%dpadLEFT_pressed%]
		 ;Sleep, 2000	
		  Send {Left down}
		  Sleep, 50
		  Send {Left up}
   		 }


;**********
;D-PAD RIGHT
;**********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 dpadRIGHT_pressed := state.wButtons & 8
   	 if(dpadRIGHT_pressed)
		 {
       		 ;Msgbox, Does this work [%dpadRIGHT_pressed%]
		 ;Sleep, 2000	
		  Send {Right down}
		  Sleep, 50
		  Send {Right up}
   		 }

;**********
;START
;**********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 start_pressed := state.wButtons & 16
   	 if(start_pressed)
		 {
       		 ;Msgbox, Does this work [%start_pressed%]
		 ;Sleep, 2000	
		  Send {S down}
		  Sleep, 50
		  Send {S up}
   		 }

;**********
;BACK
;**********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 back_pressed := state.wButtons & 32
   	 if(back_pressed)
		 {
       		 ;Msgbox, Does this work [%back_pressed%]
		 ;Sleep, 2000	
		  Send {B down}
		  Sleep, 50
		  Send {B up}
   		 }

;*************
;LEFT SHOULDER
;*************
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 LShoulder_pressed := state.wButtons & 256
   	 if(LShoulder_pressed)
		 {
       		 ;Msgbox, Does this work [%LShoulder_pressed%]
		 ;Sleep, 2000	
		  Send {L down}
		  Sleep, 50
		  Send {L up}
   		 }

;**************
;RIGHT SHOULDER
;**************
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 RShoulder_pressed := state.wButtons & 512
   	 if(RShoulder_pressed)
		 {
       		 ;Msgbox, Does this work [%RShoulder_pressed%]
		 ;Sleep, 2000	
		  Send {R down}
		  Sleep, 50
		  Send {R up}
   		 }

;**************
;L-THUMB CLICK
;**************
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 LTClick_pressed := state.wButtons & 64
   	 if(LTClick_pressed)
		 {
       		 ;Msgbox, Does this work [%LTClick_pressed%]
		  Send LEFT THUMB CLICK
   		 }

;**************
;R-THUMB CLICK
;**************
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 RTClick_pressed := state.wButtons & 128
   	 if(RTClick_pressed)
		 {
       		 ;Msgbox, Does this work [%RTClick_pressed%]
		  Send RIGHT THUMB CLICK
   		 }


;**********
;L-TRIGGER
;**********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 LTrigger_pressed := state.bLeftTrigger ;the "& [insert # here]" part doesn't seem to be required for the triggers
   	 if(LTrigger_pressed)
		 {
       		 ;Msgbox, Does this work [%LTrigger_pressed%]
		 ;Sleep, 2000	
		  Send LEFT TRIGGER
   		 }

;**********
;R-TRIGGER
;**********
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 RTrigger_pressed := state.bRightTrigger ;the "& [insert # here]" part doesn't seem to be required for the triggers
   	 if(RTrigger_pressed)
		 {
       		 ;Msgbox, Does this work [%RTrigger_pressed%]
		  Send RIGHT TRIGGER
   		 }

;*******************
;L-THUMB Y AXIS DOWN
;*******************
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 LT_Yaxis_Down := state.sThumbLY & 3000
   	 if not(LT_Yaxis_Down)
		 {
       		  Msgbox, Does this work [%LT_Yaxis_Down%] pressed down
		 }

/*

;*******************
;L-THUMB Y AXIS UP
;*******************
XInput_Init()
state := Xinput_GetState(0)
if(state) 
	{
   	 LT_Yaxis_Up := state.sThumbLY & -32000
   	 if not(LT_Yaxis_Up)
		 {
       		  Msgbox, Does this work [%LT_Yaxis_Up%] pressed up
		 }
*/



Return

;The number of closed braces below will match the number of buttons/triggers/joysticks being checked above
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	;}  ;this brace is commented out currently due to commenting out "L-THUMB AXIS UP" section
	
	
F11::ExitApp
F12::Reload
F10::Pause, Toggle

; These nubmers are decimal conversions from the hexidecimal values in Xinput.ahk "Constants for gamepad buttons" section
; 4096 = A button
; 8192 = B button
; 16384 = X button
; 32768 = Y button 
; D-pad UP = 1 
; D-pad DOWN = 2 
; D-pad LEFT = 4 
; D-pad RIGHT = 8 
; Start = 16
; Back = 32
; LEFT SHOULDER = 256
; RIGHT SHOULDER = 512
; LEFT THUMB CLICK = 64
; RIGHT THUMB CLICK = 128

 

 

This is excellent! Sooooo much easier to read! Thanks for doing it, and for sharing! I will def use this execution as I keep poking away at this. The buttons/triggers were kinda easy....but the joysticks are proving to be a bit more of a challenge.

38 minutes ago, JoeViking245 said:

And here is me helping with a little code clean-up. ;) 

#Include Xinput.ahk
#Persistent

SetKeyDelay, 0, 50          ;eliminates need for send {key Down} sleep 50 send {key Up}
SetTimer, checkForJoy1, 10

checkForJoy1:

XInput_Init()
state := Xinput_GetState(0)
if(state) 
{
   a_pressed := state.wButtons & 4096   ; 4096 = A button
   b_pressed := state.wButtons & 8192   ; 8192 = B button
   x_pressed := state.wButtons & 16384  ; 16384 = X button
   y_pressed := state.wButtons & 32768  ; 32768 = Y button

   if(a_pressed)
      Send, k

   if(b_pressed)
      Send, p

   if(x_pressed)
      Send, d
   
   if(y_pressed)
     Send, e

   Sleep, 100   ;helps reduce fast repeat. Increase or decrease as necessary
}

Start the script, open Notepad, press buttons.

 

Link to comment
Share on other sites

11 hours ago, skizzosjt said:

joysticks are proving to be a bit more of a challenge.

Added left and right Joy.  Also made the left and right Trigger to not be such a 'hair trigger'. ;) 

#Include Xinput.ahk
#Persistent

SetKeyDelay, 0, 50 
SetTimer, checkForJoy1, 10

checkForJoy1:

XInput_Init()
state := Xinput_GetState(0)

If(state)
{
    If(state.wButtons & 4096)   ;A button
        Send, k
    If(state.wButtons & 8192)   ;B button
        Send, p
    If(state.wButtons & 16384)  ;X button
        Send, d
    If(state.wButtons & 32768)  ;Y button
        Send, e

    If(state.wButtons & 1)      ;D-Pad UP
        Send, D-Pad Up
    If(state.wButtons & 2)      ;D-Pad Down
        Send, D-Pad Down
    If(state.wButtons & 4)      ;D-Pad Left
        Send, D-Pad Left
    If(state.wButtons & 8)      ;D-Pad Right
        Send, D-Pad Right

    If(state.wButtons & 16)      ;Start
        Send, Start
    If(state.wButtons & 32)      ;Back
        Send, Back

    If(state.wButtons & 256)     ;Left Shoulder
        Send, Left Shoulder
    If(state.wButtons & 512)     ;Right Shoulder
        Send, Right Shoulder

    If(state.wButtons & 64)      ;Left Thumb Click
        Send, Left Thumb Click
    If(state.wButtons & 128)     ;Right Thumb Click
        Send, Right Thumb Click

    ;If(state.bLeftTrigger)
    If(state.bLeftTrigger > 100)       ;Left Trigger (range 0 - 255)
        Send, Left Trigger
    If(state.bRightTrigger > 100)      ;Right Trigger
        Send, Right Trigger

    ;Left Joy Stick (+/- 9000 is the deadzone)
        ; Range between -32768 and 32767. 
        ; 0 = Center
    if(state.sThumbLX < -9000 && state.sThumbLX > -32768)
        Send Left joy moved Left
    if(state.sThumbLX > 9000 && state.sThumbLX < 32767)
        Send Left joy moved Right
    if(state.sThumbLy > 9000 && state.sThumbLX < 32767)
        Send Left joy moved Up
    if(state.sThumbLY < -9000 && state.sThumbLX > -32768)
        Send Left joy moved Down

    ;Right Joy Stick
    if(state.sThumbRX < -9000 && state.sThumbLX > -32768)
        Send Right joy moved Left
    if(state.sThumbRX > 9000 && state.sThumbLX < 32767)
        Send Right joy moved Right
    if(state.sThumbRy > 9000 && state.sThumbLX < 32767)
        Send Right joy moved Up
    if(state.sThumbRY < -9000 && state.sThumbLX > -32768)
        Send Right joy moved Down

    Sleep, 200
}

 

Going back to attempting to not have to use the Xinput.ahk, would you please test 'the other way' by adding a $ at the beginning and see if that "still" doesn't work for you?

$1Joy1::MsgBox You pressed A

This is my last-ditch effort to have AHK's built-in method work for others, and not need to #Include Xinput.ahk (and NOT having to have some special window open. lol).  😊  If by chance it does work, we can give you access to the Guide button as well. ;) 

  • Like 1
Link to comment
Share on other sites

I need help with a hotkey I am trying to come up with. My intended use is to have a key on my remote that sends ^!e, which then checks to see if explorer.exe is running, if not, it launches explorer.exe and stops. If it IS running when the hotkey is pressed, it kills the process. What I came up with kills explorer but immediately re-launches it with no stopping. Here is the script, maybe you can see what I cannot.

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = Explorer.exe
 
^!e::
   keywait, e
    Process,Exist,%eProc%
    If ErrorLevel != 0
    {
        Process,Close,%eProc%
        Process,WaitClose,%eProc%
Return
    }else  {
        If ErrorLevel = 0
        Run, %eProc%
    }
Return
Link to comment
Share on other sites

Spoiler
On 9/2/2022 at 11:05 AM, JoeViking245 said:

Added left and right Joy.  Also made the left and right Trigger to not be such a 'hair trigger'. ;) 

#Include Xinput.ahk
#Persistent

SetKeyDelay, 0, 50 
SetTimer, checkForJoy1, 10

checkForJoy1:

XInput_Init()
state := Xinput_GetState(0)

If(state)
{
    If(state.wButtons & 4096)   ;A button
        Send, k
    If(state.wButtons & 8192)   ;B button
        Send, p
    If(state.wButtons & 16384)  ;X button
        Send, d
    If(state.wButtons & 32768)  ;Y button
        Send, e

    If(state.wButtons & 1)      ;D-Pad UP
        Send, D-Pad Up
    If(state.wButtons & 2)      ;D-Pad Down
        Send, D-Pad Down
    If(state.wButtons & 4)      ;D-Pad Left
        Send, D-Pad Left
    If(state.wButtons & 8)      ;D-Pad Right
        Send, D-Pad Right

    If(state.wButtons & 16)      ;Start
        Send, Start
    If(state.wButtons & 32)      ;Back
        Send, Back

    If(state.wButtons & 256)     ;Left Shoulder
        Send, Left Shoulder
    If(state.wButtons & 512)     ;Right Shoulder
        Send, Right Shoulder

    If(state.wButtons & 64)      ;Left Thumb Click
        Send, Left Thumb Click
    If(state.wButtons & 128)     ;Right Thumb Click
        Send, Right Thumb Click

    ;If(state.bLeftTrigger)
    If(state.bLeftTrigger > 100)       ;Left Trigger (range 0 - 255)
        Send, Left Trigger
    If(state.bRightTrigger > 100)      ;Right Trigger
        Send, Right Trigger

    ;Left Joy Stick (+/- 9000 is the deadzone)
        ; Range between -32768 and 32767. 
        ; 0 = Center
    if(state.sThumbLX < -9000 && state.sThumbLX > -32768)
        Send Left joy moved Left
    if(state.sThumbLX > 9000 && state.sThumbLX < 32767)
        Send Left joy moved Right
    if(state.sThumbLy > 9000 && state.sThumbLX < 32767)
        Send Left joy moved Up
    if(state.sThumbLY < -9000 && state.sThumbLX > -32768)
        Send Left joy moved Down

    ;Right Joy Stick
    if(state.sThumbRX < -9000 && state.sThumbLX > -32768)
        Send Right joy moved Left
    if(state.sThumbRX > 9000 && state.sThumbLX < 32767)
        Send Right joy moved Right
    if(state.sThumbRy > 9000 && state.sThumbLX < 32767)
        Send Right joy moved Up
    if(state.sThumbRY < -9000 && state.sThumbLX > -32768)
        Send Right joy moved Down

    Sleep, 200
}

 

Going back to attempting to not have to use the Xinput.ahk, would you please test 'the other way' by adding a $ at the beginning and see if that "still" doesn't work for you?

$1Joy1::MsgBox You pressed A

This is my last-ditch effort to have AHK's built-in method work for others, and not need to #Include Xinput.ahk (and NOT having to have some special window open. lol).  😊  If by chance it does work, we can give you access to the Guide button as well. ;) 

 

 

thanks a lot for your help here with the script add on and clean up!

 

Unfortunately on my end I have had no luck with using the method detailed in the AHK docs you're asking about. I went about it from every angle and interpretation I could think of without success. I never did get that that MsgBox to show up!

 

I think this is a very useable script, but I'm finding some flaws going this route. Not surprisingly if the timer is set too quick it will poll the buttons so frequent you will almost certainly get multiple outputs per a single input. If you set a key delay or the timer too slow/long, now you've missed your inputs and it will feel the game is unresponsive. I don't know if there is a good set it and forget it position. Depending on the game and the gamer, it will need to adjusted accordingly. It doesn't understand a held down button the way I imagined, but it may not matter. Holding a button down will send multiple outputs. Sure keyboards do the same, but I'm not 100% if that is how controllers work. As in holding button "A" to make your character jump higher is different than tapping "A" a dozen times, with this script behaving in the tapping a dozens times method. The tapping action may not register with the game the same way a held down button does. I had a feeling this might be the case, but I think it will be frustrating for most to use this since it doesn't mask the inputs. For ex if you for some reason you no longer want the "A" button on the controller to make your character jump, you want it to be "B", which is normally fire weapon......then when you hit "B" it will still read the normal button press of fire weapon AND the new one jump. This may not be super useful to the average gamer as a result. It will do just fine in certain scenarios though

 

 

  • Like 1
Link to comment
Share on other sites

8 minutes ago, CtinD said:

I need help with a hotkey I am trying to come up with. My intended use is to have a key on my remote that sends ^!e, which then checks to see if explorer.exe is running, if not, it launches explorer.exe and stops. If it IS running when the hotkey is pressed, it kills the process. What I came up with kills explorer but immediately re-launches it with no stopping. Here is the script, maybe you can see what I cannot.

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = Explorer.exe
 
^!e::
   keywait, e
    Process,Exist,%eProc%
    If ErrorLevel != 0
    {
        Process,Close,%eProc%
        Process,WaitClose,%eProc%
Return
    }else  {
        If ErrorLevel = 0
        Run, %eProc%
    }
Return

 

 

Sure, try this out. I just tried this and it works fine. I tested it with MS Paint and Windows Explorer. Please note that closing Windows Explorer this way results in it restarting immediately afterwards. It's no different than going into task manager and kill the process that way. It automatically resurrects itself

If you really need that keywait line, add it back in. But I didn't think it was required, same goes for the WaitClose line. I'm not exactly sure why anyone would want to process kill Windows Explorer?

 

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = Explorer.exe
 
^!e::
    Process,Exist,%eProc%
    If ErrorLevel != 0
        Process,Close,%eProc%

    If ErrorLevel = 0
        Run, %eProc%
Return

 

Link to comment
Share on other sites

49 minutes ago, skizzosjt said:

 

 

Sure, try this out. I just tried this and it works fine. I tested it with MS Paint and Windows Explorer. Please note that closing Windows Explorer this way results in it restarting immediately afterwards. It's no different than going into task manager and kill the process that way. It automatically resurrects itself

If you really need that keywait line, add it back in. But I didn't think it was required, same goes for the WaitClose line. I'm not exactly sure why anyone would want to process kill Windows Explorer?

 

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = Explorer.exe
 
^!e::
    Process,Exist,%eProc%
    If ErrorLevel != 0
        Process,Close,%eProc%

    If ErrorLevel = 0
        Run, %eProc%
Return

 

Thank you for replying, I see exactly what is going on now. Is there any other way to kill explorer without it resurrecting itself? When I kill explorer in Task Manager, it doesn't do this, same with from a batch file.

Link to comment
Share on other sites

54 minutes ago, CtinD said:

Thank you for replying, I see exactly what is going on now. Is there any other way to kill explorer without it resurrecting itself? When I kill explorer in Task Manager, it doesn't do this, same with from a batch file.

Well now you just taught me something. If you open Task Manager and select "Windows Explorer" in the "PROCESS" tab it will change the "End Task" button to "Restart", so I've always thought it could only restart (resurrect itself) this way

 

But now I see what you're talking about. If you go over to the "DETAILS" tab and select "explorer.exe"  the button stays as "End Task" and that will in fact kill it for good....do not ask me how to get it to run again from here though (without the use of the hotkey script). The hotkey does work to manually run/resurrect it....however, without such a hotkey I wouldn't know what to do.  Whenever I have had explorer get stuck in a killed state, I've had to log off, shutdown, or restart. You effectively have no way to navigate throughout the OS without it

 

So no I don't know how to do exactly what you want, but there probably is a way since we can manually navigate to such an action. If AHK can distinguish between a restart and end task through Task Manager it would be possible. The standard Process, Close command seems to be acting like it is done through the "Processes" tab meaning explorer gets restarted. It needs to send such command to the "Details" tab so it does "End Task"

 

EDIT: oh duh didn't think of this right away lol....since you got it working with a batch file you could easily have an AHK script tell this batch file to run. Something like this.....replace the Process, Close...... line with running the batch file instead.

 

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = explorer.exe
 
^!e::
    Process,Exist,%eProc%
    If ErrorLevel != 0
       Run, PATH/TO/BATCH/FILE/TO/PERMANENTLY/KILL/EXPLORER

    If ErrorLevel = 0
        Run, %eProc%   
Return

 

Edited by skizzosjt
  • Like 1
Link to comment
Share on other sites

1 hour ago, skizzosjt said:

Well now you just taught me something. If you open Task Manager and select "Windows Explorer" in the "PROCESS" tab it will change the "End Task" button to "Restart", so I've always thought it could only restart (resurrect itself) this way

 

But now I see what you're talking about. If you go over to the "DETAILS" tab and select "explorer.exe"  the button stays as "End Task" and that will in fact kill it for good....do not ask me how to get it to run again from here though (without the use of the hotkey script). The hotkey does work to manually run/resurrect it....however, without such a hotkey I wouldn't know what to do.  Whenever I have had explorer get stuck in a killed state, I've had to log off, shutdown, or restart. You effectively have no way to navigate throughout the OS without it

 

So no I don't know how to do exactly what you want, but there probably is a way since we can manually navigate to such an action. If AHK can distinguish between a restart and end task through Task Manager it would be possible. The standard Process, Close command seems to be acting like it is done through the "Processes" tab meaning explorer gets restarted. It needs to send such command to the "Details" tab so it does "End Task"

 

EDIT: oh duh didn't think of this right away lol....since you got it working with a batch file you could easily have an AHK script tell this batch file to run. Something like this.....replace the Process, Close...... line with running the batch file instead.

 

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = explorer.exe
 
^!e::
    Process,Exist,%eProc%
    If ErrorLevel != 0
       Run, PATH/TO/BATCH/FILE/TO/PERMANENTLY/KILL/EXPLORER

    If ErrorLevel = 0
        Run, %eProc%   
Return

 

LOL! I didn't even think of it like this. My reasoning is I try to keep everything within the script itself so it is self-contained, I know I can pass the argument of killing explorer via cmd but it didn't stay dead so I didn't even see it as a viable option. I am not above this though as all i have to do is keep the batch file alongside my script.

 

EDIT:

Thank you for your help @skizzosjt. I figured this out by combing both of our efforts. This is what worked for me:

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
eProc = explorer.exe
 
^!e::
   keywait, e
    Process,Exist,%eProc%
    If ErrorLevel != 0
    {
        Run, taskkill /f /IM explorer.exe
        return
    }else  {
        If ErrorLevel = 0
        Run, %eProc%
    }
Return
Edited by CtinD
Link to comment
Share on other sites

9 minutes ago, CtinD said:

My reasoning is I try to keep everything within the script itself so it is self-contained,

You can:

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = explorer.exe
 
^!e::
    Process,Exist,%eProc%
    If ErrorLevel != 0
       Run, taskkill /im %eProc% /f

    If ErrorLevel = 0
        Run, %eProc%   
Return

 

  • Like 1
Link to comment
Share on other sites

2 minutes ago, Your Friendly A.I Overlord said:

You can:

SendMode Input  ;; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ;; Ensures a consistent starting directory.
eProc = explorer.exe
 
^!e::
    Process,Exist,%eProc%
    If ErrorLevel != 0
       Run, taskkill /im %eProc% /f

    If ErrorLevel = 0
        Run, %eProc%   
Return

 

LOL! I just came up with this, thank you!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...