DivinityCycle Posted November 2, 2016 Share Posted November 2, 2016 Took waaaaaay too much messing around to figure all parts of this out, but I have finally successfully found a working solution. The problem: I use an Xbox 360 controller for most emu gaming, and wanted to use the silver "Xbox logo" Guide button on the middle of the controller as my "Get to the menus" / "Get out of this game" button. My reasoning is pretty simple: the 360 has enough controls to serve as a pretty good solution for almost all kinds of games, up to the Playstation DualShock controls. ALL the buttons on the controller will be used up if you're using a 1:1 mapping to a DualShock controller except for the Guide button. RetroArch native recognizes this button already, and I use that for most of my emulation needs. However, I honestly don't like using the libretro port of MAME, as it's got a lot of weird things going on with its implementation, particularly for controls. However, MAME does not naively recognize the Guide button, because by default it's inputs are hidden. It doesn't show up as a normal joystick button, although it IS possible to read it's inputs. My solution: Because LaunchBox is awesome, it has support for AutoHotKey scripts built right in. This means you don't have to install and manage a separate application to get AHK functionality, you can just put add a script to an emulator's config in LB and LB will make that script active when the emulator is active. This is totally perfect for my needs, as it'll make it much less annoying to use non-RetroArch stuff. This script should be usable with pretty much any program or emulator, and it's pretty simple to customize. Caveats: This took me over a week to fully figure out. One important thing to know: The 360 Guide button will sometimes already do stuff on your system. If you have Steam installed and running, Steam will automatically open up Big Picture Mode. I'm a big fan of Valve and I own like hundreds of games in Steam, so I'm not gonna stop using that. The solution comes in the form of some awesome person on the internet who compiled a custom version of the file XInput1_4.dll. This is possible because a lot of Microsoft's library sourcecode is freely available online, to better assist developers who want to use their APIs & libraries. Some frickin genius built this version of XInput1_4.dll which filters out the Guide button inputs complete. To make use of this, you simply need to drop that file into your Steam install directory (same folder where you'll find Steam.exe). Then, if Steam's already running, completed exit it out of it and then re-launch. Then press your Guide button and marvel at how it does nothing at all. If you're running Windows 10 and you play PC games, you may have run into the "Game Bar" feature. This is new thing they've built in to try and make game streaming and other social stuff easier. Annoyingly, for a lot of people running Windows 10, pressing the Guide button will launch the Game Bar. I'm finding conflicting info on the "best" way to disable this functinality. I've taken some screenshots of what worked nice & easy for me. You can actually bring up the Game Bar in almost any program, including Chrome, by either pressing Guide or Windows Key+G. That should bring up the bar (as pictured in Step1.jpg). You can get into the Settings but clicking on the gear button on the right. That'll get you into the screen I've pictured in Step2.jpg. About halfway down on the settings is the option "Open Game bar using Guide on controller". UNCHECK this option. While you're at it you'll probably want to disable the Recording option completely, unless you plan on being a Twitch star If you have enabled the GameBar in Chrome just to get to the setting, once you're done simply uncheck the "Remember this as a game" option down towards the bottom. So far in my silly emulation adventures, these are the only 2 things I've found that grab the Guide button functionality. I ran into and solved both of these a while ago when I started working on getting my RetroArch setup figured out. Onward to MAME itself! MAME has been under development for years and is the subject of a lot of discussion, so researching my issues in controlling MAME gave tons of results, with a lot of info being old & useless. One great thing I learned: the old practice of having to patch the MAME source code and compile a custom build to get DirectInput working is no more. My AHK solution is working fine with the stock standard builds of MAME available from the official site. I tested both version 178 and 179. The key thing is, some time ago the devs added command line or .ini options allowing the user to specify what methods to use for inputs. The key one to make the AHK inputs work is keyboardprovider. This option MUST be set to "dinput" (for DirectInput). Without this, MAME will not read the keystrokes coming from AHK. The simplest way to set this is to just edit your mame.ini file, but you can also add it as a command line option if you want to do that instead for some reason. The actual script itself took a lot of trial and error, because I just couldn't get MAME to read inputs at all. A lot of this was my own ignorance for how AHK scripts work, but also MAME's intolerance to using the standard "Send" or "SendInput" methods most AHK scripts employ. The trick was to explicitly send both the "key down" and "key up" events with a separate "sleep 10" in between. I originally had a lot of problems with getting input from the Guide button, but I eventually found that using the "scancode" vk07sc000:: actually does work. It randomly stopped working on me a couple of times and I honestly don't know why, but rebooting my machine restored functionality. So, here's the script I'm using to translate the 360 Guide button into a press of the Tab key: vk07sc000:: Send {Tab down} Sleep 10 Send {Tab up} return I have tested this with the current version of LaunchBox and MAME 178 and 179 and it works exactly as expected. By default the Tab key brings up the MAME OSD, allowing the user to do admin tasks like fix inputs and exit out of MAME, which is exactly what I want. You can easily change what keystroke this sends, or remap what Tab does in MAME. Hope this post helps some people out, as it was a lot of work figuring this one out XInput1_4.dll 4 Quote Link to comment Share on other sites More sharing options...
ckp Posted November 2, 2016 Share Posted November 2, 2016 Very nice @DivinityCycle!! I don't tab into MAME with my controller but it's very useful to know what is needed for MAME to listen to the ahk script!! The secret sauce you found was keyboardprovider . Thanks! Now I will assign something to my xbox guide button for mame. The command line looks like this if going that route: "-keyboardprovider dinput" Quote Link to comment Share on other sites More sharing options...
DivinityCycle Posted November 2, 2016 Author Share Posted November 2, 2016 You got it, that command line switch will over-ride the default option and/or the setting in mame.ini if one is present. Quote Link to comment Share on other sites More sharing options...
DivinityCycle Posted November 3, 2016 Author Share Posted November 3, 2016 Two addendums: I figured out how to consistently make this stop working. Still haven't worked out WHY this happens, but if you connect to the computer where you're trying to use the controller using Remote Desktop, and then log back into that machine locally, the system will no longer detect the buttonpresses. I confirmed that this is the case and also found that you don't actually have to reboot, merely logging out and back in will bring functionality back. While testing that out I also confirmed that any 360 controller connected to the same computer appears to get the same virtual scancode assigned to the Guide button, which means the script I posted will detect the Guide button presses on controller 1, 2, 3, or 4 as denoted by the LEDs on the 360 controller. Probably good to know if you're considering this method. I'm a big fan of the classic 4 player arcade action, so I plan on regularly using MAME with 4 controllers simultaneously. Quote Link to comment Share on other sites More sharing options...
Kondorito Posted May 5, 2018 Share Posted May 5, 2018 Hey @DivinityCycle! Was looking for a solution like this since a long time Thank you for all your research. I am not able to make it work however; I do not have Steam or any other app that might obstruct the Guide button. Pasted your AHK code in its correct section, and mapped the TAB key as the Config button in MAME, but nothing happens. Do you know if something changed from the MAME version you tested over a year ago and the current ones (I am on 196 just in case). Any insight you can provide regarding this will be highly appreciated. Cheers! Quote Link to comment Share on other sites More sharing options...
DivinityCycle Posted May 9, 2018 Author Share Posted May 9, 2018 I have not been working on any emulator stuff for quite a while (as my lack of activity on here would reflect). I don't even remember what OS I was using at the time, nor do I have AHK installed anymore. At some point I'll probably get back into it, but I don't want to make any commitments here that I couldn't keep, so I can't really help. ¯\_(ツ)_/¯ Quote Link to comment Share on other sites More sharing options...
sundogak Posted May 27, 2018 Share Posted May 27, 2018 Kondorito: You might double check that you have MAME keyboardprovider in the MAME.INI set to dinput as described in the script in another thread. The above should work then. That was what I had incorrect and was driving me crazy. Thus, MAME was not receiving any input even if script was correct. I elected to not modify my MAME.INI settings and instead placed a command line as suggested in the thread notes: "Open Launchbox, go to the Default Command-Line parameters for MAME and add: -keyboardprovider dinput" I modified some of the scripts in the Forum and the code below worked for me (along with using the DLL attached above since I use Steam). With one click of the XBOX Guide button it brings up the config screen and with a doubletap of the button exits out of MAME. I use double tap of Guide for other emulators as well. Retroarch I have same script but instead of {tab} I use {F1} so brings up the Retroarch menus. I am just using this for setting up now but will delete the tab/F1 portion of the script later since don't want others fiddling. ; ================================================================================= ; FOR MAME keyboardprovider IN mame.ini MUST BE SET TO dinput ; OR for Launchbox, go to the Default Command-Line parameters for MAME and add: -keyboardprovider dinput ; ================================================================================= vk07sc000:: ; XBOX ONE Guide Button if (A_PriorHotkey <> "vk07sc000" or A_TimeSincePriorHotkey > 400) { SetKeyDelay, -1, 110 send {tab} ; one press brings up MAME Configuration Menu return } Process, Close, {{{StartupEXE}}} ; Double-tap Exits MAME return Quote Link to comment Share on other sites More sharing options...
Kondorito Posted May 28, 2018 Share Posted May 28, 2018 Thank you @sundogak. I already have dinput as I needed it to map my weird fightsick with keyboard keys. I will test your script in a very short while and post results. Thanks! Quote Link to comment Share on other sites More sharing options...
Kondorito Posted May 29, 2018 Share Posted May 29, 2018 Did not work @sundogak. I have a 360 controller, not ONE (checked and the guide button for both is called the same nevertheless). I do not have steam, but I am thinking of using that DLL as maybe it helps somehow. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.