MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Pages: 1

joeisen
MAME dev newbie
Reged: 03/09/10
Posts: 7
Send PM


Sending Keys to MAME
#216824 - 03/14/10 02:26 AM


I’ve spent hours and hours on this and I can’t figure it out. Please help.

Here’s the scoop, a while back I made an onscreen game controller that I would use to control MAME. It’s a simple little windows form that simulates key presses to other applications.

Recently I decided to update my app to work with latest release of MAME and it just keeps failing. I noticed that Microsoft’s onscreen keyboard is also no longer working as an input device for MAME and I’m guessing it is failing for the same unknown reason… unknown to me that is.

My controller uses the Microsoft SendKeys() function to send key up and down messages. For grins I also tried using SendMessage() but I could see from the MAME source code (window.c) that it wasn’t going to work either as the MAME window is not processing WM_KEYDOWN messages.

I received a little glimmer of hope from an article that explained that when you use SendInput() with apps that are using DirectInput, you have to use the scan codes for DirectInput instead of virtual keys. That sounded to me like the silver bullet because I can see that the latest version of MAME is indeed using DirectInput. But alas… after hours of trying different implementations of this I could not get SendInput() to send keyboard input to MAME.

If anyone has any ideas on how to send keys to MAME please let me know. I’m desperate and almost ready to give up on this little endeavor.



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9713
Loc: ECV-197 The Orville
Send PM


Re: Sending Keys to MAME new [Re: joeisen]
#216876 - 03/14/10 09:55 PM


As we have to explain surprisingly frequently, MAME uses DirectInput in RAW mode. This is necessary to properly support multiple of each device (e.g. 2 USB keyboards, or 4 mice, or 2 lightguns, etc) but it also means there's no way to inject keypresses unless you're an actual device with a Windows driver.



Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4457
Loc: Melbourne, Australia
Send PM


Re: Sending Keys to MAME new [Re: R. Belmont]
#216885 - 03/14/10 10:52 PM


You could probably do it with a driver that presents a virtual HID interface in the way that the Wacom tablet driver does to simulate keystrokes from tablet buttons. The actual driver that communicates with the hardware is a user-mode application that sends information to a driver that raises the events.



joeisen
MAME dev newbie
Reged: 03/09/10
Posts: 7
Send PM


Re: Sending Keys to MAME new [Re: Vas Crabb]
#216903 - 03/15/10 02:06 AM


Thanks Vas, you don't happen to have any links to examples do you?



Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4457
Loc: Melbourne, Australia
Send PM


Re: Sending Keys to MAME new [Re: joeisen]
#216911 - 03/15/10 05:48 AM


Here's a thread about someone's adventures trying do do something similar on Windows 7: http://www.winvistatips.com/virtual-hid-keyboard-and-mouse-driver-t804396.html



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9713
Loc: ECV-197 The Orville
Send PM


Re: Sending Keys to MAME new [Re: Vas Crabb]
#216941 - 03/15/10 03:48 PM


> You could probably do it with a driver that presents a virtual HID interface in the
> way that the Wacom tablet driver does to simulate keystrokes from tablet buttons. The
> actual driver that communicates with the hardware is a user-mode application that
> sends information to a driver that raises the events.

Fair warning: this is a common desire of illegal cabinet owners. Don't be too helpful about it



joeisen
MAME dev newbie
Reged: 03/09/10
Posts: 7
Send PM


Re: Sending Keys to MAME new [Re: R. Belmont]
#216956 - 03/15/10 06:43 PM


Thank you very much. That certainly clears it up.

I know that modifying the mame source is probably out of scope for this forum, but I'm going to ask anyway

If I were to modify osd/windows/input.c like so (line 517):

// initialize RawInput and DirectInput (RawInput first so we can fall back)
//rawinput_init(machine);
dinput_init(machine);
win32_init(machine);

Would that possibly work? I just stop it from initiating raw input. According to the comment, it sounds like it will fall back.



Vas Crabb
BOFH
Reged: 12/13/05
Posts: 4457
Loc: Melbourne, Australia
Send PM


Re: Sending Keys to MAME new [Re: R. Belmont]
#216970 - 03/15/10 10:53 PM


> Fair warning: this is a common desire of illegal cabinet owners. Don't be too helpful about it

Remember I'm a UNIX developer at heart - my knowledge of how to actually do this is very limited, so I'm not actually capable of being very helpful.



joeisen
MAME dev newbie
Reged: 03/09/10
Posts: 7
Send PM


Re: Sending Keys to MAME new [Re: Vas Crabb]
#216974 - 03/15/10 11:21 PM


Oh c'mon guys, I'm not trying to do anything sneaky, I just want my onscreen controller to work

Thanks for your help.



HowardC
MAME Fan
Reged: 05/15/04
Posts: 177
Send PM


Re: Sending Keys to MAME new [Re: joeisen]
#217841 - 03/25/10 10:49 PM


There is your problem... you are trying to send keyboard input. Try joystick input, it's much simplier.

And considering all the shady things that COULD be done with such a technique, I'll leave you to google the answers on your own. I will tell you that glovepie has a really good working example.



joeisen
MAME dev newbie
Reged: 03/09/10
Posts: 7
Send PM


Re: Sending Keys to MAME new [Re: HowardC]
#217872 - 03/26/10 01:55 AM


I actually got this working. I had a little help from a friend of mine who developed a very extensive onboard keyboard for tablet computers.

So now I have this verion of MAME that runs on touch screens. It's pretty nifty too. I'd like to share it with the community but I have no idea where to start.

Part of my modification also included making it work as a child window in a WPF application. Is modifying the source MAME as I have considered taboo? I think this is a really cool variation and I'd like to contribute it if possible.



Counter Force
MAME Wannabi
Reged: 06/25/10
Posts: 9
Send PM


Re: Sending Keys to MAME new [Re: joeisen]
#225518 - 06/26/10 04:08 AM


Thats fantastic!
good job



Lord Nightmare
Speech Synth Berzerker
Reged: 03/08/04
Posts: 855
Loc: PA, USA
Send PM


Re: Sending Keys to MAME new [Re: joeisen]
#225745 - 06/28/10 09:20 AM


> I actually got this working. I had a little help from a friend of mine who developed
> a very extensive onboard keyboard for tablet computers.
>
> So now I have this verion of MAME that runs on touch screens. It's pretty nifty too.
> I'd like to share it with the community but I have no idea where to start.
>
> Part of my modification also included making it work as a child window in a WPF
> application. Is modifying the source MAME as I have considered taboo? I think this is
> a really cool variation and I'd like to contribute it if possible.

Sure, share it. As long as it doesn't do anything against the MAME license, its fine.

LN



"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"



headkaze
MAME Fan
Reged: 10/31/05
Posts: 21
Send PM


Re: Sending Keys to MAME new [Re: joeisen]
#246022 - 02/07/11 11:10 PM


Digging up an old thread here but I thought I'd post what I've done in the past.

- The simplest way to inject keys into MAME is to compile a custom version with the following #define set to 1. The file is src\osd\windows\input.c


Code:

#define FORCE_DIRECTINPUT	1



SendInput() works with DirectInput

- You can inject keys into MAME by attaching a dll to the MAME process and API hook the RawInput calls.
- You can use a key to joystick app such as PPJoy or VJoy



Thad
MAME Fan
Reged: 07/10/11
Posts: 1
Send PM


Re: Sending Keys to MAME new [Re: HowardC]
#259492 - 07/10/11 04:02 AM


Hi -- sorry to walk right in and necro an old thread, but I've been working on a similar project and HowardC's post jumped out at me:

> There is your problem... you are trying to send keyboard input. Try joystick input,
> it's much simplier.

That sounds like a great idea but I'm at a bit of a loss on where to start.

Bit of background: I'm trying to get a decent Wii Remote gaming setup under Windows. Both OSX and Linux have pretty good keyboard emulation libraries for the remote, but the best thing Windows seems to have is GlovePIE, which, while an interesting and admirable piece of software, seems a bit hacky and has some rather bizarre license terms.

There are a few good libraries out for the Wii Remote; I'm currently working with the C#-based WiimoteLib but I'm not married to it. I've rigged it up to simulate keyboard presses using SendInput(), but as the OP notes that doesn't work for DirectInput.

Now, I stumbled across this thread looking for a solution to simulate keypresses using DirectInput, but HowardC makes an excellent point: joystick input would be much better for my purposes (since I'm using a game controller, after all).

So how WOULD I go about sending joystick data to MAME or similar programs? Do I need something like VJoy or PPJoy, as mentioned in headkaze's post? The Wii Remote DOES show up under Game Controllers in the Control Panel but shows no buttons or joysticks when you pull up its properties.

(I could, of course, use my current SendInput() keyboard emulation code WITH VJoy to get joystick output, but that seems needlessly convoluted -- using a game controller to emulate a keyboard emulating a game controller.)

Anyway, any ideas appreciated; thanks for reading this far.



Dr_Lagaffe
MAME Fan
Reged: 09/05/11
Posts: 1
Send PM


Re: Sending Keys to MAME new [Re: headkaze]
#264027 - 09/06/11 09:58 AM


Hi HeadKaze, if you are still keeping an eye on this thread...

I am trying to do exactly what you are mentioning without any success.
I compiled mame 0.142 with the FORCE_DIRECTINPUT 1 option. I have a hook that will identify any pressed keys. When I press the key 6 I want the soft to send '5'.
The key is sent to any apps but Mame !!!

I have tried to use :
keybd_event
and
SendInput

Can you share a code example with us... Or do you have any tips to make it run ?

I am able to make my 'multicoin' using autohotkey (which does not need to have a kind of keylogger runing around) but as a tutorial purpose I would like to be able to code it with regular C/C++, but without any success yet.


Thanks

Edited by Dr_Lagaffe (09/06/11 11:33 AM)



SpecialEffect
MAME Fan
Reged: 10/03/11
Posts: 2
Send PM


Accessibility Issues for Disabled Gamers new [Re: Dr_Lagaffe]
#265536 - 10/03/11 02:01 PM


This is a very hopeful post, as it likely goes against current MAME philosphy, and Microsoft recommendations...

I work for the accessible gaming charity SpecialEffect, where we try to remove barriers that can disable people from being able to play.

MAME in the past has been a wonderful thing for accessible gaming, thanks to the reconfigurable control options, cheat modes and massively, its compatiblity with accessible gaming hardware and utilities.

Sadly, a big chunk of this accessibility went with the introduction of reading input devices RAW.

Such utilities that no longer work in MAME that once did include: Microsoft's "On Screen Keyboard"; "Track Mapper" which used to allow head-mouse users to play keyboard only games; "4 Noah" which enabled up to six buttons to be reduced down to a single key; And recently, the "Alt-Controller" utility used at EuroGamer this year, that allowed eye-gaze control over keyboard only game Track-Mania.

Now, I understand that RAW offers benefits for a number of multi-player games, and for ultimate purists, the original coin-op games never allowed you to use different control methods, but until recently, MAME offered a way to level the playing field for disabled gamers. And with Star ROMs in the past, or in PCB ownership - there is a legitimate way in too.

So, in a big plea-styley, is there any chance that MAME devs could offer an accessibility option that gives a way back in for these devices that use "scan codes" or "virtual keycodes" for modern computers? It would be an amazing add, and would re-open up games that a number of people used to play, but no longer can due to disability. It will also mean that if current MAME users were to become disabled in future life, they'll still be very likely to keep playing with a little support.

Barrie Ellis
Accessibility Technical Specialist - SpecialEffect.org.uk



R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9713
Loc: ECV-197 The Orville
Send PM


Re: Accessibility Issues for Disabled Gamers new [Re: SpecialEffect]
#265544 - 10/03/11 04:27 PM


> So, in a big plea-styley, is there any chance that MAME devs could offer an
> accessibility option that gives a way back in for these devices that use "scan codes"
> or "virtual keycodes" for modern computers? It would be an amazing add, and would
> re-open up games that a number of people used to play, but no longer can due to
> disability. It will also mean that if current MAME users were to become disabled in
> future life, they'll still be very likely to keep playing with a little support.

We'd certainly accept patches that added explicit support for various accessibility devices. (Not having any, we can't add the support ourselves). And I wish people with genuine use cases like yours would have spoken up sooner. 99% of people asking about this stuff want it for novelty or illegal purposes, which tends to harden MAMEdev's response to such questions.

That said, the MUCH lower resistance method is to simply build SDLMAME for Windows, which AFAIK is fully vulnerable to all the classic key-injection hacks. We include everything you need to do that in the base source and the base compile tools; you simply 'make OSD=sdl' instead of plain 'make' when building.



SpecialEffect
MAME Fan
Reged: 10/03/11
Posts: 2
Send PM


Re: Accessibility Issues for Disabled Gamers new [Re: R. Belmont]
#266611 - 10/17/11 11:04 AM


> > So, in a big plea-styley, is there any chance that MAME devs could offer an
> > accessibility option that gives a way back in for these devices that use "scan
> codes"
> > or "virtual keycodes" for modern computers? It would be an amazing add, and would
> > re-open up games that a number of people used to play, but no longer can due to
> > disability. It will also mean that if current MAME users were to become disabled in
> > future life, they'll still be very likely to keep playing with a little support.
>
> We'd certainly accept patches that added explicit support for various accessibility
> devices. (Not having any, we can't add the support ourselves). And I wish people with
> genuine use cases like yours would have spoken up sooner. 99% of people asking about
> this stuff want it for novelty or illegal purposes, which tends to harden MAMEdev's
> response to such questions.
>
> That said, the MUCH lower resistance method is to simply build SDLMAME for Windows,
> which AFAIK is fully vulnerable to all the classic key-injection hacks. We include
> everything you need to do that in the base source and the base compile tools; you
> simply 'make OSD=sdl' instead of plain 'make' when building.

Thanks for replying. I wish I'd got this plea in earlier. You can test MAME for accessibility with these kind of utilties if you have a PC to hand with XP, Vista or Win 7. With Win 7, type "on screen keyboard" in the Start Search bar, then click on that utility. If you can get that to work with MAME, many other utilities will follow. If you have a USB joystick, you can also test out with JoyToKey here: http://www.oneswitch.org.uk/2/I/JoyToKey/JoyToKey.htm and 4Noah: http://www.oneswitch.org.uk/2/I/4Noah/gaming-switch.htm

Sadly, I just don't have the skills, nor time to develop the skills, to build a fix for new versions of MAME... So if there's anyone out there who might be able to help... Please do get in touch. Would be great to open up MAME again for greater access.



tapley
MAME Fan
Reged: 08/31/19
Posts: 1
Send PM


Re: Sending Keys to MAME new [Re: Dr_Lagaffe]
#383492 - 08/31/19 01:54 PM


Replying to a super old post here, but I figured this out running MAME 0.212 on a Win 10 machine

Ensure you start MAME up with this option
-keyboardprovider dinput

Then you can use the Windows SendInput API using direct api key codes (instead of VK_*)

See the code on github account for anyone to look at if anyone is interested

https://github.com/stevetapley/mame-ai/tree/master/SendInputDemo



MetalGod
MAME Fan
Reged: 06/26/18
Posts: 117
Send PM


Re: Sending Keys to MAME new [Re: joeisen]
#383590 - 09/08/19 03:33 AM


edit

Edited by MetalGod (09/08/19 03:34 AM)



Camame
MAME Fan
Reged: 08/14/23
Posts: 1
Send PM


Re: Sending Keys to MAME new [Re: tapley]
#396842 - 08/14/23 03:05 AM


Thank you so much in 2023 for this final piece of the puzzle I had in hands over the weekend. I made a usb coin acceptor based on arduino but as my arduino uno's chip cant be flashed to hid, I could not send direct key strokes to mame. I decided to link arduino to python and make a code using a keyboard library, but mame would not recognize the key press, then found a directinput keyboard library which I thought might work but mame would still not register any keyboard press when a coin was inserted. Changing keyboard provider to dinput on mame.ini upon your suggestion finally helped me resolve it! Thank you!


Pages: 1

MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 7 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 18001