Main > Software Forum

MAME source

<< < (2/2)

cpetzol2:
Im sorry this is lengthy, but any code I have ever written was so much less complicated and organized as the MAME code, I need to make sure I am doing this correctly.

So, I am in the main MAME folder, and go to ui.c. I find handler_ingame(), and set up a fuction that checks for about 5 different keypresses. If it finds one of these presses, it will create a structure that says one of my keys was pressed and then it will say which ones, so the structure will have 6 variables in it.

Then, I want to go into the Windows folder, and find input.c. I find wininput_poll(), and right before the lines


--- Code: ---// update the lagged keyboard
updatekeyboard();
--- End code ---

I will set up such a routine.


--- Code: ---if(flag_from_handler_ingame)
       switch (key_id)
       {
                case key_1: keyboard_state[0][DIK_ESC] = 0x80;
                case key_2:keyboard_state[0][DIK_MENU] = 0x80;
                case key_3:keyboard_state[0][DIK_1] = 0x80;
                case key_4:keyboard_state[0][DIK_2] = 0x80;
                case key_5:keyboard_state[0][DIK_5] = 0x80;


--- End code ---

Is this correct. If more than one of my keys are pressed, can I can keyboard_state[][] twice in a row. Should I use DIK CODES like I did?

Is there a better way to detect certain keypresses rather than adding onto handler_ingame()? Will there be performance issues, such as, handler_ingame only gets called once a second, therefore some keyinjections will be late?

If someone has a little time, and knows of a much more robust way of doing this, or an easier way than what I have above, I would definitly appreciate it. Thank you

headkaze:
First of all you could probably do all this without the need to modify the Mame source at all. Check out the scripting capabilities of AutoHotkey and AutoIt3. You can map any key to any other key or key combination with one line of code, and it will compile your script into an executable if you like. I highly recommend you check these out.

Second like I said in my previous posts IDirectInputDevice_GetDeviceState() or GetAsyncKeyState() is when Mame reads the raw data from the keyboard. So why place your code in handler_ingame(), you can do it all in the wininput_poll() function and then you know all the keys will be processed correctly.

So just before the "update the lagged keyboard" line in windows\input.c\wininput_poll()

--- Code: ---for (i = 0; i < keyboard_count; i++)
{
    if(keyboard_state[i][DIK_??] & 0x80) { keyboard_state[i][DIK_??] = 0; keyboard_state[0][DIK_ESC] = 0x80; }
    if(keyboard_state[i][DIK_??] & 0x80) { keyboard_state[i][DIK_??] = 0; keyboard_state[0][DIK_MENU] = 0x80; }
    if(keyboard_state[i][DIK_??] & 0x80) { keyboard_state[i][DIK_??] = 0; keyboard_state[0][DIK_1] = 0x80; }
    if(keyboard_state[i][DIK_??] & 0x80) { keyboard_state[i][DIK_??] = 0; keyboard_state[0][DIK_2] = 0x80; }
    if(keyboard_state[i][DIK_??] & 0x80) { keyboard_state[i][DIK_??] = 0; keyboard_state[0][DIK_5] = 0x80; }
}
--- End code ---

Obviously replace DIK_?? with the keys you are checking for. This will loop through all keyboards checking for whatever keys you want, then it will clear the keypress if found (important unless you want that key to be processed as well), then set it to key you want into keyboard 0, or you could of course inject it back into the same keyboard i if you wanted to.

But like I said in my first paragraph your going the long way about mapping keys if that's all you want to do.

BTW I noticed in your switch() statement you didn't use a break; after each case, which is not good.

Navigation

[0] Message Index

[*] Previous page

Go to full version