Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Autohotkey for enabling VJOY for MK X  (Read 3807 times)

0 Members and 1 Guest are viewing this topic.

Moksi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 194
  • Last login:April 20, 2024, 01:12:43 pm
  • I want to build my own arcade controls!
Autohotkey for enabling VJOY for MK X
« on: November 08, 2017, 12:10:13 pm »
I got the script from someone on hyperspin forum , it doesnt work flawless yet

this is to enable the Vjoy virtual Joystick Driver only when launching exmple MK X

because this  driver interferes with other things like emulators , controls setup for taito type x is then seen as an xbox controller & not keyboard

So the main reason is to only enable the driver when launching MK X & Disable the driver when MK X exits.
Which can be done with a program called devcon

I got a launch & close scripts

Launch
---------------
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

SetBatchLines -1


Run, C:\Windows\System32\devcon.exe enable vjoy*
Run, C:\Program Files (x86)\VJoy\VJoy.exe -file "C:\Program Files (x86)\Vjoy\MK10.ini"
Run, C:\Program Files (x86)\Steam\SteamApps\common\MK10\Binaries\Retail\MK10.exe
-----------------------------------------------------------------------------------
the script will work if the command prompt is run as administrator , i tested it in command prompt enabling disabling the driver.
not if it isnt run as administrator

How can i edit the script to get the command prompt to launch as admin & execute enabling / disabling vjoy

Cause the way it is now it isnt working out of the box


Any help appriciated

spacorn

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 18
  • Last login:August 29, 2022, 10:46:45 am
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #1 on: November 08, 2017, 06:23:27 pm »
Sometimes Autohotkey has troubles running stuff that require elevated rights. Try running the script as administrator. If it works, you can set the Autohotkey exe itself to always open as administrator in the compatibily tab in the file's properties, this will give elevated rights to all your scripts.

Moksi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 194
  • Last login:April 20, 2024, 01:12:43 pm
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #2 on: November 09, 2017, 04:13:44 pm »
Thanks, im gonna try to see if it works

Moksi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 194
  • Last login:April 20, 2024, 01:12:43 pm
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #3 on: November 10, 2017, 06:11:21 am »
I tried it but it will ask for confirmation everytime & in hyperspin it doesnt show the confirmation

i dont know if its possible to get autohokey to start an elevated shortcut of the command prompt or autohotkey itself

spacorn

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 18
  • Last login:August 29, 2022, 10:46:45 am
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #4 on: November 10, 2017, 09:58:57 am »
You could try making a .bat file for running/closing the problematic program. You could probably do all you need with a single .bat instead of an AHK script anyway, but if you want it to integrate this to your existing script, you could open the .bat file from your script in hidden mode, so you never see the command prompt, like this:

Run %YourBat%,, Hide

That way it would work exactly as if your .ahk did everything by itself.
I know it's an ugly solution, but it should work. I've used to successfully open/close programs with elevated rights that Autohotkey scripts can't handle even when opened with elevated rights itself (in my case it was Touchmote, the wiimote driver).


rablack97

  • Trade Count: (+3)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2215
  • Last login:May 11, 2022, 06:50:10 pm
  • If you don't try, you have no chance at innovation
Re: Autohotkey for enabling VJOY for MK X
« Reply #5 on: November 10, 2017, 05:15:48 pm »
its been ages, but i built a custom cab around MKX PC version, prior to netherrealm stopping support.

Was able to boot into MKX via hyperspin with controls enabled no issues w/vjoy.  I dont recall having to do what all your trying to do to get it to work.

Moksi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 194
  • Last login:April 20, 2024, 01:12:43 pm
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #6 on: November 11, 2017, 04:33:54 am »
i want to enable the Vjoy driver only with certain Games like MK X & MK Komplete edition & when i exit the game disabling the Vjoy driver

it interferes with other emulators control type is not seen as keyboard

Moksi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 194
  • Last login:April 20, 2024, 01:12:43 pm
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #7 on: November 11, 2017, 04:36:31 am »
You could try making a .bat file for running/closing the problematic program. You could probably do all you need with a single .bat instead of an AHK script anyway, but if you want it to integrate this to your existing script, you could open the .bat file from your script in hidden mode, so you never see the command prompt, like this:

Run %YourBat%,, Hide

That way it would work exactly as if your .ahk did everything by itself.
I know it's an ugly solution, but it should work. I've used to successfully open/close programs with elevated rights that Autohotkey scripts can't handle even when opened with elevated rights itself (in my case it was Touchmote, the wiimote driver).

wow i have no knowledge with .bat files

how can i make a bat file that enables vjoy driver (Device Manager) & disabling the driver when you exit the game ?

spacorn

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 18
  • Last login:August 29, 2022, 10:46:45 am
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #8 on: December 25, 2017, 05:43:01 pm »
(Sorry, I hadn't been on this board for awhile, I missed you post. I hope you solved your problem by now. But just in case, I'm gonna answer what you asked)

You can attach to a .bat anything you can do on a command prompt, so whatever you need to automate, you can follow a basic command prompt syntax guide for that.

For example, to start/stop a windows service you can use:

net start <service executable name>
net stop <service executable name>


To enable/disable devices, you need an external file called devcon.exe (which you can find anywhere in the net if it isn't already in your system, but I'm gonna attach it just in case). You can run it through a .bat (or autohotkey script, or just a shortcut with parameters):

devcon.exe <switch> <device HID>

You can check the target device's HID code in the device manager (properties > details > hardware id)

Examples:

devcon.exe enable HID\VID_057E&PID_0306&REV_0100&MI_00
devcon.exe disable HID\VID_057E&PID_0306&REV_0100&MI_00
devcon.exe remove HID\VID_057E&PID_0306&REV_0100&MI_00
devcon.exe rescan


I recommend to only enable/disable since removing/rescaning all the time can get messy...
And, whatever you do, remember you can have these .bat runs hidden and completely silent on the background if you run them hidden mode (either natively or through the autohotkey example I gave you on my previous post)

Anyway, as rablack97 said, this workaround may not be all that necessary after all, and I hope you've fixed/can fix your problem in a more elegant way... but it never hurts to know your options!  :D
« Last Edit: December 25, 2017, 06:11:21 pm by spacorn »

Moksi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 194
  • Last login:April 20, 2024, 01:12:43 pm
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #9 on: January 01, 2018, 03:50:13 pm »
I just gave it up after alot of attempts , glad you responded

i just did a test and it works , but if i run the enable vjoy .bat it aks for confirmation
If i have this bat to make it run as an admin so that it doesnt ask for confirmation its perfect
as i use Hyperspin with an x Arcade tankstick

How can i make the bat enable disable vjoy as administrator ?

With the   "Run %YourBat%,, Hide" command ?     
« Last Edit: January 02, 2018, 01:15:02 pm by Moksi »

spacorn

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 18
  • Last login:August 29, 2022, 10:46:45 am
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #10 on: January 07, 2018, 02:26:19 pm »
I've never been asked for confirmation... probably because I run devcon.exe from Autohotkey scripts, and I've setup Autohotkey to always run with elevated rights, so everything I run from it will run with elevated rights itself...
Maybe you could try that (right click on the main Autohotkey.exe in program files, the option is in Properties, Compatibility)

Your AHK script line to work on devcon.exe should look like this:

Run devcon.exe remove HID\VID_057E&PID_0306&REV_0100&MI_00
Exitapp


(I'll keep using my random HID so you get exactly how it would look. Also I'm assuming everything is on the same path. If not, you should replace all exe calls with the full path, example: "c:\whatever\devcon.exe", quotation marks and all, instead of just devcon.exe)

If you set up Autohotkey to always run with elevated right you shouldn't need any confirmation with a script like that. If it works, you can add the "Hide" parameter so the command line windows run silently, like:

Run devcon.exe remove HID\VID_057E&PID_0306&REV_0100&MI_00,, Hide
Exitapp


Note the double comma, it's because every comma in AHK syntax marks a different parameter. In this case, the entire run command is parameter 1, then we're leaving the 2nd parameter blank (which is changing the starting directory, it defaults to the executable's path), and the 3rd parameter is where "Hide" should be.

If it works, you could even setup a single launcher file that does everything for you:

Run devcon.exe disable HID\VID_057E&PID_0306&REV_0100&MI_00
RunWait MKX.exe
Run devcon.exe enable HID\VID_057E&PID_0306&REV_0100&MI_00
Exitapp


What that would:

1. disables the device through devcon
2. runs you main app (in this case I'm assuming it's mkx.exe), and waits for it process to close. Once it closes...
3. reenables the device through devcon

And again, once you confirm that works as expected, you can add the "Hide" parameter to the devcon prompts

Run devcon.exe disable HID\VID_057E&PID_0306&REV_0100&MI_00,, Hide
RunWait MKX.exe
Run devcon.exe enable HID\VID_057E&PID_0306&REV_0100&MI_00,, Hide
Exitapp


See if that works. If you don't want to work with AHK and do everythign through bats you'll have to figure that out yourself, I know AHK way more than I know regular bat scripts at this point  :P

Also, keep in mind AHK scripts can be compiled into standalone EXE files... So if you don't want to setup the main Autohotkey.exe file to always run as administrator for some reason, you can always compile this script alone (once you confirm it works reliably), and only set this particular EXE to run with elevated rights.

Another possible problem you can have with the "do it all" script is that some programs don't use the same process all the way through (for example, some games that open from some kind of launcher before opening the main game from a different exe file, and the launching process AHK waits to be closed closes before the main game does). In a case like that you'll have to figure out another way of correctly detecting when the game closes (there's several ways to do that). You probably won't have this problem but I wanted to mention it just in case you start writing similar scripts to solve other problems with other games. Once you get the hang of it it's very fun to be able to fix every little nuance you thought you had no control over  :P
« Last Edit: January 07, 2018, 02:29:04 pm by spacorn »

Moksi

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 194
  • Last login:April 20, 2024, 01:12:43 pm
  • I want to build my own arcade controls!
Re: Autohotkey for enabling VJOY for MK X
« Reply #11 on: January 07, 2018, 03:46:47 pm »
Wow i gave up on autohotkey after trying to run it with elevated rights it still brings up the confirmation window , also trying to run it with elevated rights in task scheduler.

then i saw your post about the .bat file  & maybe a .bat file with the commands should work

the autohotkey someone made has 2 two files enable vjoy when mkx starts en disables vjoy when mkx exits & then set it up with rocketlauncher

so how do you put it into one bat file?  doesnt really matter to me as long as this admin thing doesnt bug with the .bat

i have the autohotkey in the program files folder maybe thats why its stubborn with the admin rights , but if some how i managed to workaround it with the .bat file i m happy