Separated input from mapinput
This commit is contained in:
parent
c59c9d8626
commit
880030665f
|
@ -133,24 +133,8 @@ static unsigned char *keys=0;
|
|||
static unsigned char *keys_nr=0;
|
||||
static int DIPS=0;
|
||||
|
||||
static uint8 keyonce[MKK_COUNT];
|
||||
//#define KEY(__a) keys_nr[MKK(__a)]
|
||||
|
||||
static int _keyonly(int a)
|
||||
{
|
||||
if(keys_nr[a])
|
||||
{
|
||||
if(!keyonce[a])
|
||||
{
|
||||
keyonce[a]=1;
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
keyonce[a]=0;
|
||||
return(0);
|
||||
}
|
||||
|
||||
int cidisabled=0;
|
||||
|
||||
#define MK(x) {{BUTTC_KEYBOARD},{0},{MKK(x)},1}
|
||||
|
@ -1389,17 +1373,6 @@ void DestroyInput(void)
|
|||
}
|
||||
}
|
||||
|
||||
#define CMD_KEY_MASK 0xff
|
||||
#define CMD_KEY_LSHIFT (1<<16)
|
||||
#define CMD_KEY_RSHIFT (1<<17)
|
||||
#define CMD_KEY_SHIFT (CMD_KEY_LSHIFT|CMD_KEY_RSHIFT)
|
||||
#define CMD_KEY_LCTRL (1<<18)
|
||||
#define CMD_KEY_RCTRL (1<<19)
|
||||
#define CMD_KEY_CTRL (CMD_KEY_LCTRL|CMD_KEY_RCTRL)
|
||||
#define CMD_KEY_LALT (1<<20)
|
||||
#define CMD_KEY_RALT (1<<21)
|
||||
#define CMD_KEY_ALT (CMD_KEY_LALT|CMD_KEY_RALT)
|
||||
|
||||
int FCEUD_CommandMapping[EMUCMD_MAX];
|
||||
|
||||
CFGSTRUCT HotkeyConfig[]={
|
||||
|
@ -1407,88 +1380,6 @@ CFGSTRUCT HotkeyConfig[]={
|
|||
ENDCFGSTRUCT
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
int cmd;
|
||||
int key;
|
||||
} DefaultCommandMapping[]=
|
||||
{
|
||||
{ EMUCMD_RESET, SCAN_R | CMD_KEY_CTRL },
|
||||
{ EMUCMD_PAUSE, SCAN_F2, },
|
||||
{ EMUCMD_FRAME_ADVANCE, SCAN_TAB, },
|
||||
{ EMUCMD_SCREENSHOT, SCAN_F9 },
|
||||
{ EMUCMD_HIDE_MENU_TOGGLE, SCAN_ESCAPE },
|
||||
{ EMUCMD_SPEED_SLOWER, SCAN_MINUS, }, // think about these
|
||||
{ EMUCMD_SPEED_FASTER, SCAN_EQUAL, }, // think about these
|
||||
{ EMUCMD_SPEED_TURBO, SCAN_GRAVE, }, //tilde
|
||||
{ EMUCMD_SAVE_SLOT_0, SCAN_0, },
|
||||
{ EMUCMD_SAVE_SLOT_1, SCAN_1, },
|
||||
{ EMUCMD_SAVE_SLOT_2, SCAN_2, },
|
||||
{ EMUCMD_SAVE_SLOT_3, SCAN_3, },
|
||||
{ EMUCMD_SAVE_SLOT_4, SCAN_4, },
|
||||
{ EMUCMD_SAVE_SLOT_5, SCAN_5, },
|
||||
{ EMUCMD_SAVE_SLOT_6, SCAN_6, },
|
||||
{ EMUCMD_SAVE_SLOT_7, SCAN_7, },
|
||||
{ EMUCMD_SAVE_SLOT_8, SCAN_8, },
|
||||
{ EMUCMD_SAVE_SLOT_9, SCAN_9, },
|
||||
{ EMUCMD_SAVE_STATE, SCAN_F5, },
|
||||
{ EMUCMD_LOAD_STATE, SCAN_F7, },
|
||||
//get feedback from TAS people about these
|
||||
/*{ EMUCMD_MOVIE_FRAME_DISPLAY_TOGGLE, SCAN_PERIOD, },
|
||||
{ EMUCMD_FDS_EJECT_INSERT, SCAN_F8, },
|
||||
{ EMUCMD_FDS_SIDE_SELECT, SCAN_F6, },
|
||||
{ EMUCMD_MOVIE_INPUT_DISPLAY_TOGGLE, SCAN_COMMA, },
|
||||
{ EMUCMD_MOVIE_READONLY_TOGGLE, SCAN_8 | CMD_KEY_SHIFT, },*/
|
||||
{ EMUCMD_MISC_REWIND, SCAN_R, },
|
||||
//mbg 7/31/06 - these have been removed as defaults until we decide whether hotkey philosophy permits them
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_0, SCAN_F10 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_1, SCAN_F1 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_2, SCAN_F2 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_3, SCAN_F3 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_4, SCAN_F4 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_5, SCAN_F5 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_6, SCAN_F6 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_7, SCAN_F7 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_8, SCAN_F8 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_9, SCAN_F9 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_0, SCAN_F10, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_1, SCAN_F1, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_2, SCAN_F2, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_3, SCAN_F3, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_4, SCAN_F4, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_5, SCAN_F5, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_6, SCAN_F6, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_7, SCAN_F7, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_8, SCAN_F8, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_9, SCAN_F9, },
|
||||
/* { EMUCMD_MOVIE_SLOT_0, SCAN_0 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_1, SCAN_1 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_2, SCAN_2 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_3, SCAN_3 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_4, SCAN_4 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_5, SCAN_5 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_6, SCAN_6 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_7, SCAN_7 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_8, SCAN_8 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_9, SCAN_9 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_RECORD, SCAN_F5 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_REPLAY, SCAN_F7 | CMD_KEY_ALT, },*/
|
||||
};
|
||||
|
||||
#define NUM_DEFAULT_MAPPINGS (sizeof(DefaultCommandMapping)/sizeof(DefaultCommandMapping[0]))
|
||||
|
||||
void ApplyDefaultCommandMapping(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(FCEUD_CommandMapping, 0, sizeof(FCEUD_CommandMapping));
|
||||
|
||||
for(i=0; i<NUM_DEFAULT_MAPPINGS; ++i)
|
||||
{
|
||||
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd] = DefaultCommandMapping[i].key;
|
||||
}
|
||||
}
|
||||
|
||||
int FCEUD_TestCommandState(int c)
|
||||
{
|
||||
int cmd=FCEUD_CommandMapping[c];
|
||||
|
@ -1558,472 +1449,6 @@ int FCEUD_TestCommandState(int c)
|
|||
return keys[cmdmask] ? 1 : 0;
|
||||
}
|
||||
|
||||
static const char* ScanNames[256]=
|
||||
{
|
||||
/* 0x00-0x0f */ 0, "Escape", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Minus", "Equals", "Backspace", "Tab",
|
||||
/* 0x10-0x1f */ "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "Enter", "Left Ctrl", "A", "S",
|
||||
/* 0x20-0x2f */ "D", "F", "G", "H", "J", "K", "L", "Semicolon", "Apostrophe", "Tilde", "Left Shift", "Backslash", "Z", "X", "C", "V",
|
||||
/* 0x30-0x3f */ "B", "N", "M", "Comma", "Period", "Slash", "Right Shift", "Numpad *", "Left Alt", "Space", "Caps Lock", "F1", "F2", "F3", "F4", "F5",
|
||||
/* 0x40-0x4f */ "F6", "F7", "F8", "F9", "F10", "NumLock", "ScrollLock", "Numpad 7", "Numpad 8", "Numpad 9", "Numpad Minus", "Numpad 4", "Numpad 5", "Numpad 6", "Numpad Plus", "Numpad 1",
|
||||
/* 0x50-0x5f */ "Numpad 2", "Numpad 3", "Numpad 0", "Numpad Period", 0, 0, "Backslash", "F11", "F12", 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x60-0x6f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x70-0x7f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x80-0x8f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x90-0x9f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Numpad Enter", "Right Ctrl", 0, 0,
|
||||
/* 0xa0-0xaf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xb0-0xbf */ 0, 0, 0, 0, 0, "Numpad Divide", 0, "PrintScrn", "Right Alt", 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xc0-0xcf */ 0, 0, 0, 0, 0, "Pause", 0, "Home", "Up Arrow", "PgUp", 0, "Left Arrow", 0, "Right Arrow", 0, "End",
|
||||
/* 0xd0-0xdf */ "Down Arrow", "PgDn", "Ins", "Del", 0, 0, 0, 0, 0, 0, 0, "Left Win", "Right Win", "AppMenu", 0, 0,
|
||||
/* 0xe0-0xef */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xf0-0xff */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
static const char* GetKeyName(int code)
|
||||
{
|
||||
static char name[16];
|
||||
|
||||
code &= 0xff;
|
||||
if(ScanNames[code])
|
||||
return ScanNames[code];
|
||||
|
||||
sprintf(name, "Key 0x%.2x", code);
|
||||
return name;
|
||||
}
|
||||
|
||||
static char* GetKeyComboName(int c)
|
||||
{
|
||||
static char text[80];
|
||||
|
||||
text[0]='\0';
|
||||
if(!c)
|
||||
return text;
|
||||
|
||||
if ((c & CMD_KEY_CTRL) == CMD_KEY_CTRL) strcat(text, "Ctrl + ");
|
||||
else if ((c & CMD_KEY_CTRL) == CMD_KEY_LCTRL) strcat(text, "Left Ctrl + ");
|
||||
else if ((c & CMD_KEY_CTRL) == CMD_KEY_RCTRL) strcat(text, "Right Ctrl + ");
|
||||
if ((c & CMD_KEY_ALT) == CMD_KEY_ALT) strcat(text, "Alt + ");
|
||||
else if ((c & CMD_KEY_ALT) == CMD_KEY_LALT) strcat(text, "Left Alt + ");
|
||||
else if ((c & CMD_KEY_ALT) == CMD_KEY_RALT) strcat(text, "Right Alt + ");
|
||||
if ((c & CMD_KEY_SHIFT) == CMD_KEY_SHIFT) strcat(text, "Shift + ");
|
||||
else if ((c & CMD_KEY_SHIFT) == CMD_KEY_LSHIFT) strcat(text, "Left Shift + ");
|
||||
else if ((c & CMD_KEY_SHIFT) == CMD_KEY_RSHIFT) strcat(text, "Right Shift + ");
|
||||
|
||||
strcat(text, GetKeyName(c & CMD_KEY_MASK));
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
struct INPUTDLGTHREADARGS
|
||||
{
|
||||
HANDLE hThreadExit;
|
||||
HWND hwndDlg;
|
||||
};
|
||||
|
||||
static DWORD WINAPI NewInputDialogThread(LPVOID lpvArg)
|
||||
{
|
||||
struct INPUTDLGTHREADARGS* args = (struct INPUTDLGTHREADARGS*)lpvArg;
|
||||
|
||||
while (args->hThreadExit)
|
||||
{
|
||||
if (WaitForSingleObject(args->hThreadExit, 20) == WAIT_OBJECT_0)
|
||||
break;
|
||||
|
||||
// Poke our owner dialog periodically.
|
||||
PostMessage(args->hwndDlg, WM_USER, 0, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int GetKeyPressed()
|
||||
{
|
||||
int key=0;
|
||||
int i;
|
||||
|
||||
keys_nr=GetKeyboard_nr();
|
||||
|
||||
for(i=0; i<256 && !key; ++i)
|
||||
{
|
||||
if(_keyonly(i))
|
||||
key=i;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
static int NothingPressed()
|
||||
{
|
||||
int i;
|
||||
|
||||
keys_nr=GetKeyboard_nr();
|
||||
|
||||
for(i=0; i<256; ++i)
|
||||
{
|
||||
if(keys_nr[i])
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int GetKeyMeta(int key)
|
||||
{
|
||||
int meta = key & (~CMD_KEY_MASK);
|
||||
switch(key & CMD_KEY_MASK)
|
||||
{
|
||||
case SCAN_LEFTCONTROL:
|
||||
case SCAN_RIGHTCONTROL: return CMD_KEY_CTRL | meta;
|
||||
case SCAN_LEFTALT:
|
||||
case SCAN_RIGHTALT: return CMD_KEY_ALT | meta;
|
||||
case SCAN_LEFTSHIFT:
|
||||
case SCAN_RIGHTSHIFT: return CMD_KEY_SHIFT | meta;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
static void ClearExtraMeta(int* key)
|
||||
{
|
||||
switch((*key)&0xff)
|
||||
{
|
||||
case SCAN_LEFTCONTROL:
|
||||
case SCAN_RIGHTCONTROL: *key &= ~(CMD_KEY_CTRL); break;
|
||||
case SCAN_LEFTALT:
|
||||
case SCAN_RIGHTALT: *key &= ~(CMD_KEY_ALT); break;
|
||||
case SCAN_LEFTSHIFT:
|
||||
case SCAN_RIGHTSHIFT: *key &= ~(CMD_KEY_SHIFT); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL CALLBACK ChangeInputDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
static HANDLE hThread = NULL;
|
||||
static DWORD dwThreadId = 0;
|
||||
static struct INPUTDLGTHREADARGS threadargs;
|
||||
static int key=0;
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
// Start the message thread.
|
||||
threadargs.hThreadExit = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
threadargs.hwndDlg = hwndDlg;
|
||||
hThread = CreateThread(NULL, 0, NewInputDialogThread, (LPVOID)&threadargs, 0, &dwThreadId);
|
||||
key=0;
|
||||
memset(keyonce, 0, sizeof(keyonce));
|
||||
KeyboardSetBackgroundAccess(1);
|
||||
SetFocus(GetDlgItem(hwndDlg, 100));
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if(LOWORD(wParam) == 202 && HIWORD(wParam) == BN_CLICKED)
|
||||
{
|
||||
key=0;
|
||||
PostMessage(hwndDlg, WM_USER+1, 0, 0); // Send quit message.
|
||||
}
|
||||
else if(LOWORD(wParam) == 200 && HIWORD(wParam) == BN_CLICKED)
|
||||
{
|
||||
key=-1;
|
||||
PostMessage(hwndDlg, WM_USER+1, 0, 0); // Send quit message.
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WM_USER:
|
||||
{
|
||||
// Our thread sent us a timer signal.
|
||||
int newkey;
|
||||
int meta=GetKeyMeta(key);
|
||||
|
||||
KeyboardUpdateState();
|
||||
|
||||
if((newkey=GetKeyPressed()) != 0)
|
||||
{
|
||||
key = newkey | meta;
|
||||
ClearExtraMeta(&key);
|
||||
SetDlgItemText(hwndDlg, 100, GetKeyComboName(key));
|
||||
}
|
||||
else if(NothingPressed() && key)
|
||||
PostMessage(hwndDlg, WM_USER+1, 0, 0); // Send quit message.
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_USER+1:
|
||||
{
|
||||
// Done with keyboard.
|
||||
KeyboardSetBackgroundAccess(0);
|
||||
|
||||
// Kill the thread.
|
||||
SetEvent(threadargs.hThreadExit);
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
CloseHandle(threadargs.hThreadExit);
|
||||
|
||||
// End the dialog.
|
||||
EndDialog(hwndDlg, key);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static int* ConflictTable=0;
|
||||
|
||||
static int ShouldDisplayMapping(int mapn, int filter)
|
||||
{
|
||||
//mbg merge 7/17/06 changed to if..elseif
|
||||
if(filter==0) /* No filter */
|
||||
return 1;
|
||||
else if(filter <= EMUCMDTYPE_MAX) /* Filter by type */
|
||||
return (FCEUI_CommandTable[mapn].type == filter-1);
|
||||
else if(filter == EMUCMDTYPE_MAX+1) /* Assigned */
|
||||
return FCEUD_CommandMapping[mapn];
|
||||
else if(filter == EMUCMDTYPE_MAX+2) /* Unassigned */
|
||||
return !(FCEUD_CommandMapping[mapn]);
|
||||
else if(filter == EMUCMDTYPE_MAX+3) /* Conflicts */
|
||||
return ConflictTable[mapn];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void PopulateMappingDisplay(HWND hwndDlg)
|
||||
{
|
||||
LVITEM lvi;
|
||||
int i;
|
||||
int idx;
|
||||
HWND hwndListView = GetDlgItem(hwndDlg, 1003);
|
||||
int num=SendMessage(hwndListView, LVM_GETITEMCOUNT, 0, 0);
|
||||
int filter = (int)SendDlgItemMessage(hwndDlg, 300, CB_GETCURSEL, 0, 0);
|
||||
|
||||
// Delete everything in the current display.
|
||||
for(i=num; i>0; --i)
|
||||
SendMessage(hwndListView, LVM_DELETEITEM, (WPARAM)i-1, 0);
|
||||
|
||||
// Get the filter type.
|
||||
ConflictTable=0;
|
||||
if (filter == EMUCMDTYPE_MAX+3)
|
||||
{
|
||||
// Set up the conflict table.
|
||||
ConflictTable=(int*)malloc(sizeof(int)*EMUCMD_MAX);
|
||||
memset(ConflictTable, 0, sizeof(int)*EMUCMD_MAX);
|
||||
for(i=0; i<EMUCMD_MAX-1; ++i)
|
||||
{
|
||||
int j;
|
||||
for(j=i+1; j<EMUCMD_MAX; ++j)
|
||||
{
|
||||
if(FCEUD_CommandMapping[i] &&
|
||||
FCEUD_CommandMapping[i] == FCEUD_CommandMapping[j])
|
||||
{
|
||||
ConflictTable[i]=1;
|
||||
ConflictTable[j]=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Populate display.
|
||||
for(i=0, idx=0; i<EMUCMD_MAX; ++i)
|
||||
{
|
||||
if(ShouldDisplayMapping(i, filter))
|
||||
{
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT | LVIF_PARAM;
|
||||
lvi.iItem = idx;
|
||||
lvi.iSubItem = 0;
|
||||
lvi.pszText = (char*)FCEUI_CommandTypeNames[FCEUI_CommandTable[i].type];
|
||||
lvi.lParam = (LPARAM)i;
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT;
|
||||
lvi.iItem = idx;
|
||||
lvi.iSubItem = 1;
|
||||
lvi.pszText = FCEUI_CommandTable[i].name;
|
||||
|
||||
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT;
|
||||
lvi.iItem = idx;
|
||||
lvi.iSubItem = 2;
|
||||
lvi.pszText = GetKeyComboName(FCEUD_CommandMapping[i]);
|
||||
|
||||
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
if(ConflictTable)
|
||||
free(ConflictTable);
|
||||
}
|
||||
|
||||
static BOOL CALLBACK MapInputDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
HWND hwndListView = GetDlgItem(hwndDlg, 1003);
|
||||
LVCOLUMN lv;
|
||||
//LVITEM lvi; //mbg merge 7/17/06 removed
|
||||
int i;
|
||||
|
||||
// Set full row select.
|
||||
SendMessage(hwndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
|
||||
|
||||
// Init ListView columns.
|
||||
memset(&lv, 0, sizeof(lv));
|
||||
lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
||||
lv.fmt = LVCFMT_LEFT;
|
||||
lv.pszText = "Type";
|
||||
lv.cx = 40;
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTCOLUMN, (WPARAM)0, (LPARAM)&lv);
|
||||
|
||||
memset(&lv, 0, sizeof(lv));
|
||||
lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
||||
lv.fmt = LVCFMT_LEFT;
|
||||
lv.pszText = "Command";
|
||||
lv.cx = 180;
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTCOLUMN, (WPARAM)1, (LPARAM)&lv);
|
||||
|
||||
memset(&lv, 0, sizeof(lv));
|
||||
lv.mask = LVCF_FMT | LVCF_TEXT;
|
||||
lv.fmt = LVCFMT_LEFT;
|
||||
lv.pszText = "Input";
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTCOLUMN, (WPARAM)2, (LPARAM)&lv);
|
||||
|
||||
// Populate the filter combobox.
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, 0, (LPARAM)"None");
|
||||
for(i=0; i<EMUCMDTYPE_MAX; ++i)
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, i+1, (LPARAM)FCEUI_CommandTypeNames[i]);
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, ++i, (LPARAM)"Assigned");
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, ++i, (LPARAM)"Unassigned");
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, ++i, (LPARAM)"Conflicts");
|
||||
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_SETCURSEL, 0, 0); // Default filter is "none".
|
||||
|
||||
// Now populate the mapping display.
|
||||
PopulateMappingDisplay(hwndDlg);
|
||||
|
||||
// Autosize last column.
|
||||
SendMessage(hwndListView, LVM_SETCOLUMNWIDTH, (WPARAM)2, MAKELPARAM(LVSCW_AUTOSIZE_USEHEADER, 0));
|
||||
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if(HIWORD(wParam) == CBN_SELCHANGE)
|
||||
{
|
||||
PopulateMappingDisplay(hwndDlg);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
case IDOK:
|
||||
EndDialog(hwndDlg, 1);
|
||||
return TRUE;
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog(hwndDlg, 0);
|
||||
return TRUE;
|
||||
|
||||
case 200:
|
||||
ApplyDefaultCommandMapping();
|
||||
PopulateMappingDisplay(hwndDlg);
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
case 1003:
|
||||
if (lParam)
|
||||
{
|
||||
HWND hwndListView = GetDlgItem(hwndDlg, 1003);
|
||||
NMHDR* pnm = (NMHDR*)lParam;
|
||||
if (pnm->code == LVN_ITEMACTIVATE)
|
||||
{
|
||||
int nSel = SendMessage(hwndListView, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED);
|
||||
if (nSel != -1)
|
||||
{
|
||||
int nCmd;
|
||||
int nRet;
|
||||
LVITEM lvi;
|
||||
|
||||
// Get the corresponding input
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_PARAM;
|
||||
lvi.iItem = nSel;
|
||||
lvi.iSubItem = 0;
|
||||
SendMessage(hwndListView, LVM_GETITEM, 0, (LPARAM)&lvi);
|
||||
nCmd = lvi.lParam;
|
||||
|
||||
nRet = DialogBox(fceu_hInstance,"NEWINPUT",hwndListView,ChangeInputDialogProc);
|
||||
if (nRet)
|
||||
{
|
||||
// nRet will be -1 when the user selects "clear".
|
||||
FCEUD_CommandMapping[nCmd] = (nRet<0) ? 0 : nRet;
|
||||
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT;
|
||||
lvi.iItem = nSel;
|
||||
lvi.iSubItem = 2;
|
||||
lvi.pszText = GetKeyComboName(FCEUD_CommandMapping[nCmd]);
|
||||
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show input mapping configuration dialog.
|
||||
**/
|
||||
void MapInput(void)
|
||||
{
|
||||
// Make a backup of the current mappings, in case the user changes their mind.
|
||||
int* backupmapping = (int*)malloc(sizeof(FCEUD_CommandMapping));
|
||||
memcpy(backupmapping, FCEUD_CommandMapping, sizeof(FCEUD_CommandMapping));
|
||||
|
||||
if(!DialogBox(fceu_hInstance, "MAPINPUT", hAppWnd, MapInputDialogProc))
|
||||
{
|
||||
memcpy(FCEUD_CommandMapping, backupmapping, sizeof(FCEUD_CommandMapping));
|
||||
}
|
||||
|
||||
free(backupmapping);
|
||||
}
|
||||
|
||||
void FCEUD_TurboOn(void)
|
||||
{
|
||||
//NoWaiting|=1;
|
||||
|
|
|
@ -3,6 +3,17 @@
|
|||
|
||||
#include "dinput.h"
|
||||
|
||||
#define CMD_KEY_MASK 0xff
|
||||
#define CMD_KEY_LSHIFT (1<<16)
|
||||
#define CMD_KEY_RSHIFT (1<<17)
|
||||
#define CMD_KEY_SHIFT (CMD_KEY_LSHIFT|CMD_KEY_RSHIFT)
|
||||
#define CMD_KEY_LCTRL (1<<18)
|
||||
#define CMD_KEY_RCTRL (1<<19)
|
||||
#define CMD_KEY_CTRL (CMD_KEY_LCTRL|CMD_KEY_RCTRL)
|
||||
#define CMD_KEY_LALT (1<<20)
|
||||
#define CMD_KEY_RALT (1<<21)
|
||||
#define CMD_KEY_ALT (CMD_KEY_LALT|CMD_KEY_RALT)
|
||||
|
||||
void ConfigInput(HWND hParent);
|
||||
int InitDInput(void);
|
||||
void CreateInputStuff(void);
|
||||
|
@ -54,6 +65,9 @@ void FCEUD_UpdateInput();
|
|||
|
||||
extern const char* ScanNames[];
|
||||
extern CFGSTRUCT HotkeyConfig[];
|
||||
|
||||
extern int FCEUD_CommandMapping[EMUCMD_MAX];
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,575 @@
|
|||
#include "common.h"
|
||||
#include "mapinput.h"
|
||||
#include "input.h"
|
||||
#include "keyscan.h"
|
||||
#include "keyboard.h"
|
||||
#include "../../input.h"
|
||||
|
||||
static int* ConflictTable=0;
|
||||
static uint8 keyonce[MKK_COUNT];
|
||||
static unsigned char *keys_nr=0;
|
||||
|
||||
void KeyboardUpdateState(void); //mbg merge 7/17/06 yech had to add this
|
||||
|
||||
static const char* ScanNames[256]=
|
||||
{
|
||||
/* 0x00-0x0f */ 0, "Escape", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Minus", "Equals", "Backspace", "Tab",
|
||||
/* 0x10-0x1f */ "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "[", "]", "Enter", "Left Ctrl", "A", "S",
|
||||
/* 0x20-0x2f */ "D", "F", "G", "H", "J", "K", "L", "Semicolon", "Apostrophe", "Tilde", "Left Shift", "Backslash", "Z", "X", "C", "V",
|
||||
/* 0x30-0x3f */ "B", "N", "M", "Comma", "Period", "Slash", "Right Shift", "Numpad *", "Left Alt", "Space", "Caps Lock", "F1", "F2", "F3", "F4", "F5",
|
||||
/* 0x40-0x4f */ "F6", "F7", "F8", "F9", "F10", "NumLock", "ScrollLock", "Numpad 7", "Numpad 8", "Numpad 9", "Numpad Minus", "Numpad 4", "Numpad 5", "Numpad 6", "Numpad Plus", "Numpad 1",
|
||||
/* 0x50-0x5f */ "Numpad 2", "Numpad 3", "Numpad 0", "Numpad Period", 0, 0, "Backslash", "F11", "F12", 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x60-0x6f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x70-0x7f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x80-0x8f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0x90-0x9f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Numpad Enter", "Right Ctrl", 0, 0,
|
||||
/* 0xa0-0xaf */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xb0-0xbf */ 0, 0, 0, 0, 0, "Numpad Divide", 0, "PrintScrn", "Right Alt", 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xc0-0xcf */ 0, 0, 0, 0, 0, "Pause", 0, "Home", "Up Arrow", "PgUp", 0, "Left Arrow", 0, "Right Arrow", 0, "End",
|
||||
/* 0xd0-0xdf */ "Down Arrow", "PgDn", "Ins", "Del", 0, 0, 0, 0, 0, 0, 0, "Left Win", "Right Win", "AppMenu", 0, 0,
|
||||
/* 0xe0-0xef */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 0xf0-0xff */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
struct INPUTDLGTHREADARGS
|
||||
{
|
||||
HANDLE hThreadExit;
|
||||
HWND hwndDlg;
|
||||
};
|
||||
|
||||
static int _keyonly(int a)
|
||||
{
|
||||
if(keys_nr[a])
|
||||
{
|
||||
if(!keyonce[a])
|
||||
{
|
||||
keyonce[a]=1;
|
||||
return(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
keyonce[a]=0;
|
||||
return(0);
|
||||
}
|
||||
|
||||
static int GetKeyPressed()
|
||||
{
|
||||
int key=0;
|
||||
int i;
|
||||
|
||||
keys_nr=GetKeyboard_nr();
|
||||
|
||||
for(i=0; i<256 && !key; ++i)
|
||||
{
|
||||
if(_keyonly(i))
|
||||
key=i;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
static int NothingPressed()
|
||||
{
|
||||
int i;
|
||||
|
||||
keys_nr=GetKeyboard_nr();
|
||||
|
||||
for(i=0; i<256; ++i)
|
||||
{
|
||||
if(keys_nr[i])
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int GetKeyMeta(int key)
|
||||
{
|
||||
int meta = key & (~CMD_KEY_MASK);
|
||||
switch(key & CMD_KEY_MASK)
|
||||
{
|
||||
case SCAN_LEFTCONTROL:
|
||||
case SCAN_RIGHTCONTROL: return CMD_KEY_CTRL | meta;
|
||||
case SCAN_LEFTALT:
|
||||
case SCAN_RIGHTALT: return CMD_KEY_ALT | meta;
|
||||
case SCAN_LEFTSHIFT:
|
||||
case SCAN_RIGHTSHIFT: return CMD_KEY_SHIFT | meta;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
static void ClearExtraMeta(int* key)
|
||||
{
|
||||
switch((*key)&0xff)
|
||||
{
|
||||
case SCAN_LEFTCONTROL:
|
||||
case SCAN_RIGHTCONTROL: *key &= ~(CMD_KEY_CTRL); break;
|
||||
case SCAN_LEFTALT:
|
||||
case SCAN_RIGHTALT: *key &= ~(CMD_KEY_ALT); break;
|
||||
case SCAN_LEFTSHIFT:
|
||||
case SCAN_RIGHTSHIFT: *key &= ~(CMD_KEY_SHIFT); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static DWORD WINAPI NewInputDialogThread(LPVOID lpvArg)
|
||||
{
|
||||
struct INPUTDLGTHREADARGS* args = (struct INPUTDLGTHREADARGS*)lpvArg;
|
||||
|
||||
while (args->hThreadExit)
|
||||
{
|
||||
if (WaitForSingleObject(args->hThreadExit, 20) == WAIT_OBJECT_0)
|
||||
break;
|
||||
|
||||
// Poke our owner dialog periodically.
|
||||
PostMessage(args->hwndDlg, WM_USER, 0, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct
|
||||
{
|
||||
int cmd;
|
||||
int key;
|
||||
} DefaultCommandMapping[]=
|
||||
{
|
||||
{ EMUCMD_RESET, SCAN_R | CMD_KEY_CTRL },
|
||||
{ EMUCMD_PAUSE, SCAN_F2, },
|
||||
{ EMUCMD_FRAME_ADVANCE, SCAN_TAB, },
|
||||
{ EMUCMD_SCREENSHOT, SCAN_F9 },
|
||||
{ EMUCMD_HIDE_MENU_TOGGLE, SCAN_ESCAPE },
|
||||
{ EMUCMD_SPEED_SLOWER, SCAN_MINUS, }, // think about these
|
||||
{ EMUCMD_SPEED_FASTER, SCAN_EQUAL, }, // think about these
|
||||
{ EMUCMD_SPEED_TURBO, SCAN_GRAVE, }, //tilde
|
||||
{ EMUCMD_SAVE_SLOT_0, SCAN_0, },
|
||||
{ EMUCMD_SAVE_SLOT_1, SCAN_1, },
|
||||
{ EMUCMD_SAVE_SLOT_2, SCAN_2, },
|
||||
{ EMUCMD_SAVE_SLOT_3, SCAN_3, },
|
||||
{ EMUCMD_SAVE_SLOT_4, SCAN_4, },
|
||||
{ EMUCMD_SAVE_SLOT_5, SCAN_5, },
|
||||
{ EMUCMD_SAVE_SLOT_6, SCAN_6, },
|
||||
{ EMUCMD_SAVE_SLOT_7, SCAN_7, },
|
||||
{ EMUCMD_SAVE_SLOT_8, SCAN_8, },
|
||||
{ EMUCMD_SAVE_SLOT_9, SCAN_9, },
|
||||
{ EMUCMD_SAVE_STATE, SCAN_F5, },
|
||||
{ EMUCMD_LOAD_STATE, SCAN_F7, },
|
||||
//get feedback from TAS people about these
|
||||
/*{ EMUCMD_MOVIE_FRAME_DISPLAY_TOGGLE, SCAN_PERIOD, },
|
||||
{ EMUCMD_FDS_EJECT_INSERT, SCAN_F8, },
|
||||
{ EMUCMD_FDS_SIDE_SELECT, SCAN_F6, },
|
||||
{ EMUCMD_MOVIE_INPUT_DISPLAY_TOGGLE, SCAN_COMMA, },
|
||||
{ EMUCMD_MOVIE_READONLY_TOGGLE, SCAN_8 | CMD_KEY_SHIFT, },*/
|
||||
{ EMUCMD_MISC_REWIND, SCAN_R, },
|
||||
//mbg 7/31/06 - these have been removed as defaults until we decide whether hotkey philosophy permits them
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_0, SCAN_F10 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_1, SCAN_F1 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_2, SCAN_F2 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_3, SCAN_F3 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_4, SCAN_F4 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_5, SCAN_F5 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_6, SCAN_F6 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_7, SCAN_F7 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_8, SCAN_F8 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_SAVE_STATE_SLOT_9, SCAN_F9 | CMD_KEY_SHIFT, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_0, SCAN_F10, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_1, SCAN_F1, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_2, SCAN_F2, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_3, SCAN_F3, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_4, SCAN_F4, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_5, SCAN_F5, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_6, SCAN_F6, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_7, SCAN_F7, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_8, SCAN_F8, },
|
||||
//{ EMUCMD_LOAD_STATE_SLOT_9, SCAN_F9, },
|
||||
/* { EMUCMD_MOVIE_SLOT_0, SCAN_0 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_1, SCAN_1 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_2, SCAN_2 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_3, SCAN_3 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_4, SCAN_4 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_5, SCAN_5 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_6, SCAN_6 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_7, SCAN_7 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_8, SCAN_8 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_SLOT_9, SCAN_9 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_RECORD, SCAN_F5 | CMD_KEY_ALT, },
|
||||
{ EMUCMD_MOVIE_REPLAY, SCAN_F7 | CMD_KEY_ALT, },*/
|
||||
};
|
||||
|
||||
#define NUM_DEFAULT_MAPPINGS (sizeof(DefaultCommandMapping)/sizeof(DefaultCommandMapping[0]))
|
||||
|
||||
static const char* GetKeyName(int code)
|
||||
{
|
||||
static char name[16];
|
||||
|
||||
code &= 0xff;
|
||||
if(ScanNames[code])
|
||||
return ScanNames[code];
|
||||
|
||||
sprintf(name, "Key 0x%.2x", code);
|
||||
return name;
|
||||
}
|
||||
|
||||
static char* GetKeyComboName(int c)
|
||||
{
|
||||
static char text[80];
|
||||
|
||||
text[0]='\0';
|
||||
if(!c)
|
||||
return text;
|
||||
|
||||
if ((c & CMD_KEY_CTRL) == CMD_KEY_CTRL) strcat(text, "Ctrl + ");
|
||||
else if ((c & CMD_KEY_CTRL) == CMD_KEY_LCTRL) strcat(text, "Left Ctrl + ");
|
||||
else if ((c & CMD_KEY_CTRL) == CMD_KEY_RCTRL) strcat(text, "Right Ctrl + ");
|
||||
if ((c & CMD_KEY_ALT) == CMD_KEY_ALT) strcat(text, "Alt + ");
|
||||
else if ((c & CMD_KEY_ALT) == CMD_KEY_LALT) strcat(text, "Left Alt + ");
|
||||
else if ((c & CMD_KEY_ALT) == CMD_KEY_RALT) strcat(text, "Right Alt + ");
|
||||
if ((c & CMD_KEY_SHIFT) == CMD_KEY_SHIFT) strcat(text, "Shift + ");
|
||||
else if ((c & CMD_KEY_SHIFT) == CMD_KEY_LSHIFT) strcat(text, "Left Shift + ");
|
||||
else if ((c & CMD_KEY_SHIFT) == CMD_KEY_RSHIFT) strcat(text, "Right Shift + ");
|
||||
|
||||
strcat(text, GetKeyName(c & CMD_KEY_MASK));
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
void ApplyDefaultCommandMapping(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
memset(FCEUD_CommandMapping, 0, sizeof(FCEUD_CommandMapping));
|
||||
|
||||
for(i=0; i<NUM_DEFAULT_MAPPINGS; ++i)
|
||||
{
|
||||
FCEUD_CommandMapping[DefaultCommandMapping[i].cmd] = DefaultCommandMapping[i].key;
|
||||
}
|
||||
}
|
||||
|
||||
static int ShouldDisplayMapping(int mapn, int filter)
|
||||
{
|
||||
//mbg merge 7/17/06 changed to if..elseif
|
||||
if(filter==0) /* No filter */
|
||||
return 1;
|
||||
else if(filter <= EMUCMDTYPE_MAX) /* Filter by type */
|
||||
return (FCEUI_CommandTable[mapn].type == filter-1);
|
||||
else if(filter == EMUCMDTYPE_MAX+1) /* Assigned */
|
||||
return FCEUD_CommandMapping[mapn];
|
||||
else if(filter == EMUCMDTYPE_MAX+2) /* Unassigned */
|
||||
return !(FCEUD_CommandMapping[mapn]);
|
||||
else if(filter == EMUCMDTYPE_MAX+3) /* Conflicts */
|
||||
return ConflictTable[mapn];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void PopulateMappingDisplay(HWND hwndDlg)
|
||||
{
|
||||
LVITEM lvi;
|
||||
int i;
|
||||
int idx;
|
||||
HWND hwndListView = GetDlgItem(hwndDlg, 1003);
|
||||
int num=SendMessage(hwndListView, LVM_GETITEMCOUNT, 0, 0);
|
||||
int filter = (int)SendDlgItemMessage(hwndDlg, 300, CB_GETCURSEL, 0, 0);
|
||||
|
||||
// Delete everything in the current display.
|
||||
for(i=num; i>0; --i)
|
||||
SendMessage(hwndListView, LVM_DELETEITEM, (WPARAM)i-1, 0);
|
||||
|
||||
// Get the filter type.
|
||||
ConflictTable=0;
|
||||
if (filter == EMUCMDTYPE_MAX+3)
|
||||
{
|
||||
// Set up the conflict table.
|
||||
ConflictTable=(int*)malloc(sizeof(int)*EMUCMD_MAX);
|
||||
memset(ConflictTable, 0, sizeof(int)*EMUCMD_MAX);
|
||||
for(i=0; i<EMUCMD_MAX-1; ++i)
|
||||
{
|
||||
int j;
|
||||
for(j=i+1; j<EMUCMD_MAX; ++j)
|
||||
{
|
||||
if(FCEUD_CommandMapping[i] &&
|
||||
FCEUD_CommandMapping[i] == FCEUD_CommandMapping[j])
|
||||
{
|
||||
ConflictTable[i]=1;
|
||||
ConflictTable[j]=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Populate display.
|
||||
for(i=0, idx=0; i<EMUCMD_MAX; ++i)
|
||||
{
|
||||
if(ShouldDisplayMapping(i, filter))
|
||||
{
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT | LVIF_PARAM;
|
||||
lvi.iItem = idx;
|
||||
lvi.iSubItem = 0;
|
||||
lvi.pszText = (char*)FCEUI_CommandTypeNames[FCEUI_CommandTable[i].type];
|
||||
lvi.lParam = (LPARAM)i;
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT;
|
||||
lvi.iItem = idx;
|
||||
lvi.iSubItem = 1;
|
||||
lvi.pszText = FCEUI_CommandTable[i].name;
|
||||
|
||||
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT;
|
||||
lvi.iItem = idx;
|
||||
lvi.iSubItem = 2;
|
||||
lvi.pszText = GetKeyComboName(FCEUD_CommandMapping[i]);
|
||||
|
||||
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
if(ConflictTable)
|
||||
free(ConflictTable);
|
||||
}
|
||||
|
||||
static BOOL CALLBACK ChangeInputDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
static HANDLE hThread = NULL;
|
||||
static DWORD dwThreadId = 0;
|
||||
static struct INPUTDLGTHREADARGS threadargs;
|
||||
static int key=0;
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
// Start the message thread.
|
||||
threadargs.hThreadExit = CreateEvent(NULL, TRUE, FALSE, NULL);
|
||||
threadargs.hwndDlg = hwndDlg;
|
||||
hThread = CreateThread(NULL, 0, NewInputDialogThread, (LPVOID)&threadargs, 0, &dwThreadId);
|
||||
key=0;
|
||||
memset(keyonce, 0, sizeof(keyonce));
|
||||
KeyboardSetBackgroundAccess(1);
|
||||
SetFocus(GetDlgItem(hwndDlg, 100));
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if(LOWORD(wParam) == 202 && HIWORD(wParam) == BN_CLICKED)
|
||||
{
|
||||
key=0;
|
||||
PostMessage(hwndDlg, WM_USER+1, 0, 0); // Send quit message.
|
||||
}
|
||||
else if(LOWORD(wParam) == 200 && HIWORD(wParam) == BN_CLICKED)
|
||||
{
|
||||
key=-1;
|
||||
PostMessage(hwndDlg, WM_USER+1, 0, 0); // Send quit message.
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WM_USER:
|
||||
{
|
||||
// Our thread sent us a timer signal.
|
||||
int newkey;
|
||||
int meta=GetKeyMeta(key);
|
||||
|
||||
KeyboardUpdateState();
|
||||
|
||||
if((newkey=GetKeyPressed()) != 0)
|
||||
{
|
||||
key = newkey | meta;
|
||||
ClearExtraMeta(&key);
|
||||
SetDlgItemText(hwndDlg, 100, GetKeyComboName(key));
|
||||
}
|
||||
else if(NothingPressed() && key)
|
||||
PostMessage(hwndDlg, WM_USER+1, 0, 0); // Send quit message.
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_USER+1:
|
||||
{
|
||||
// Done with keyboard.
|
||||
KeyboardSetBackgroundAccess(0);
|
||||
|
||||
// Kill the thread.
|
||||
SetEvent(threadargs.hThreadExit);
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
CloseHandle(hThread);
|
||||
CloseHandle(threadargs.hThreadExit);
|
||||
|
||||
// End the dialog.
|
||||
EndDialog(hwndDlg, key);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK MapInputDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
HWND hwndListView = GetDlgItem(hwndDlg, 1003);
|
||||
LVCOLUMN lv;
|
||||
//LVITEM lvi; //mbg merge 7/17/06 removed
|
||||
int i;
|
||||
|
||||
// Set full row select.
|
||||
SendMessage(hwndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
|
||||
|
||||
// Init ListView columns.
|
||||
memset(&lv, 0, sizeof(lv));
|
||||
lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
||||
lv.fmt = LVCFMT_LEFT;
|
||||
lv.pszText = "Type";
|
||||
lv.cx = 40;
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTCOLUMN, (WPARAM)0, (LPARAM)&lv);
|
||||
|
||||
memset(&lv, 0, sizeof(lv));
|
||||
lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
||||
lv.fmt = LVCFMT_LEFT;
|
||||
lv.pszText = "Command";
|
||||
lv.cx = 180;
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTCOLUMN, (WPARAM)1, (LPARAM)&lv);
|
||||
|
||||
memset(&lv, 0, sizeof(lv));
|
||||
lv.mask = LVCF_FMT | LVCF_TEXT;
|
||||
lv.fmt = LVCFMT_LEFT;
|
||||
lv.pszText = "Input";
|
||||
|
||||
SendMessage(hwndListView, LVM_INSERTCOLUMN, (WPARAM)2, (LPARAM)&lv);
|
||||
|
||||
// Populate the filter combobox.
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, 0, (LPARAM)"None");
|
||||
for(i=0; i<EMUCMDTYPE_MAX; ++i)
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, i+1, (LPARAM)FCEUI_CommandTypeNames[i]);
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, ++i, (LPARAM)"Assigned");
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, ++i, (LPARAM)"Unassigned");
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_INSERTSTRING, ++i, (LPARAM)"Conflicts");
|
||||
|
||||
SendDlgItemMessage(hwndDlg, 300, CB_SETCURSEL, 0, 0); // Default filter is "none".
|
||||
|
||||
// Now populate the mapping display.
|
||||
PopulateMappingDisplay(hwndDlg);
|
||||
|
||||
// Autosize last column.
|
||||
SendMessage(hwndListView, LVM_SETCOLUMNWIDTH, (WPARAM)2, MAKELPARAM(LVSCW_AUTOSIZE_USEHEADER, 0));
|
||||
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
case WM_COMMAND:
|
||||
if(HIWORD(wParam) == CBN_SELCHANGE)
|
||||
{
|
||||
PopulateMappingDisplay(hwndDlg);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
case IDOK:
|
||||
EndDialog(hwndDlg, 1);
|
||||
return TRUE;
|
||||
|
||||
case IDCANCEL:
|
||||
EndDialog(hwndDlg, 0);
|
||||
return TRUE;
|
||||
|
||||
case 200:
|
||||
ApplyDefaultCommandMapping();
|
||||
PopulateMappingDisplay(hwndDlg);
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_NOTIFY:
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
case 1003:
|
||||
if (lParam)
|
||||
{
|
||||
HWND hwndListView = GetDlgItem(hwndDlg, 1003);
|
||||
NMHDR* pnm = (NMHDR*)lParam;
|
||||
if (pnm->code == LVN_ITEMACTIVATE)
|
||||
{
|
||||
int nSel = SendMessage(hwndListView, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED);
|
||||
if (nSel != -1)
|
||||
{
|
||||
int nCmd;
|
||||
int nRet;
|
||||
LVITEM lvi;
|
||||
|
||||
// Get the corresponding input
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_PARAM;
|
||||
lvi.iItem = nSel;
|
||||
lvi.iSubItem = 0;
|
||||
SendMessage(hwndListView, LVM_GETITEM, 0, (LPARAM)&lvi);
|
||||
nCmd = lvi.lParam;
|
||||
|
||||
nRet = DialogBox(fceu_hInstance,"NEWINPUT",hwndListView,ChangeInputDialogProc);
|
||||
if (nRet)
|
||||
{
|
||||
// nRet will be -1 when the user selects "clear".
|
||||
FCEUD_CommandMapping[nCmd] = (nRet<0) ? 0 : nRet;
|
||||
|
||||
memset(&lvi, 0, sizeof(lvi));
|
||||
lvi.mask = LVIF_TEXT;
|
||||
lvi.iItem = nSel;
|
||||
lvi.iSubItem = 2;
|
||||
lvi.pszText = GetKeyComboName(FCEUD_CommandMapping[nCmd]);
|
||||
SendMessage(hwndListView, LVM_SETITEM, (WPARAM)0, (LPARAM)&lvi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show input mapping configuration dialog.
|
||||
**/
|
||||
void MapInput(void)
|
||||
{
|
||||
// Make a backup of the current mappings, in case the user changes their mind.
|
||||
int* backupmapping = (int*)malloc(sizeof(FCEUD_CommandMapping));
|
||||
memcpy(backupmapping, FCEUD_CommandMapping, sizeof(FCEUD_CommandMapping));
|
||||
|
||||
if(!DialogBox(fceu_hInstance, "MAPINPUT", hAppWnd, MapInputDialogProc))
|
||||
{
|
||||
memcpy(FCEUD_CommandMapping, backupmapping, sizeof(FCEUD_CommandMapping));
|
||||
}
|
||||
|
||||
free(backupmapping);
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef WIN_MAPINPUT_h
|
||||
#define WIN_MAPINPUT_h
|
||||
|
||||
#endif
|
|
@ -938,6 +938,14 @@
|
|||
RelativePath="..\src\drivers\win\main.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\drivers\win\mapinput.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\drivers\win\mapinput.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\drivers\win\memview.cpp"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue