Strange Direct Input Behaviour
I've made a program using Direct Input from this webpage: http://sunlightd.virtualave.net/default2.htm . Using their tutorials and code, I've been able to map keys to do different things.
The code works with an array to detect keys pressed with these two datastructures:
Code:
enum Actions
{
ACTIONS_LEFTRIGHT,
ACTIONS_LEFT,
ACTIONS_RIGHT,
ACTIONS_UP,
ACTIONS_DOWN,
ACTIONS_QUIT,
ACTIONS_HELP,
ACTIONS_PAUSE,
ACTIONS_ERROR,
ACTIONS_NONE
};
DIACTION g_rgActions[] =
{
// Genre-defined virtual axes
{ ACTIONS_LEFTRIGHT, DIAXIS_ARCADES_LATERAL, 0, "Left/Right" },
// Actions mapped to keys as well as to virtual controls
{ ACTIONS_LEFT, DIKEYBOARD_LEFT, 0, "Left" },
{ ACTIONS_LEFT, DIKEYBOARD_NUMPAD4, 0, "Left" },
{ ACTIONS_RIGHT, DIKEYBOARD_RIGHT, 0, "Right" },
{ ACTIONS_RIGHT, DIKEYBOARD_NUMPAD6, 0, "Right" },
{ ACTIONS_UP, DIKEYBOARD_UP, 0, "Up" },
{ ACTIONS_UP, DIKEYBOARD_NUMPAD8, 0, "Up" },
{ ACTIONS_DOWN, DIKEYBOARD_DOWN, 0, "Down" },
{ ACTIONS_DOWN, DIKEYBOARD_NUMPAD2, 0, "Down" },
{ ACTIONS_PAUSE, DIKEYBOARD_P, 0, "Pause" },
{ ACTIONS_HELP, DIKEYBOARD_F1, 0, "Help" },
{ ACTIONS_ERROR, DIKEYBOARD_E, 0, "ERROR" },
// Actions mapped to keys
{ ACTIONS_QUIT, DIKEYBOARD_ESCAPE, DIA_APPFIXED, "Quit" },
};
Using the simple format, I've added the ACTION_ERROR key which is suppost to keymap to the E key. However when the program is run, hitting E does nothing.
The code runs some function called ConfigureInput which shows a display box using the windows GUI where you can tell different keys to do different actions within the program.
Code:
// Display the input configuration box
BOOL ConfigureInput()
{
DICONFIGUREDEVICESPARAMS dicdp;
ZeroMemory(&dicdp, sizeof(dicdp));
dicdp.dwSize = sizeof(dicdp);
dicdp.dwcUsers = 1;
dicdp.lptszUserNames = NULL;
dicdp.dwcFormats = 1;
dicdp.lprgFormats = &g_diaf;
dicdp.hwnd = hWndMain;
dicdp.lpUnkDDSTarget = NULL;
// Set up a colour set, which will allow us to make the configuration box
// look like the rest of our program.
// If this is initialised to zero, DirectInput will use the default colour set.
dicdp.dics.dwSize = sizeof(DICOLORSET);
// Let go of any devices so that the configuration interface can have a go
UnacquireDevices();
// Display action configuration
g_pDD->FlipToGDISurface();
g_pDI->ConfigureDevices(NULL, &dicdp, DICD_EDIT, NULL);
// Devices are no longer valid, so reinitialise.
for (int iDevice = 0; iDevice < g_nDevices; iDevice++)
g_pDeviceArray[iDevice]->Release();
delete [] g_pDeviceArray;
g_pDeviceArray = NULL;
g_nDevices = 0;
HRESULT h = g_pDI->EnumDevicesBySemantics(NULL, &g_diaf,
DIEnumDevicesBySemanticsCallback,
NULL, DIEDBSFL_ATTACHEDONLY);
if (FAILED(h))
return FALSE;
AcquireDevices();
return TRUE;
}
Well, reviewing this shows that the E key is NOT mapped to anything, so using the GUI while the program is running I manually set "ERROR" to the 'e' key. Exiting the windows GUI and letting the main program run shows that the 'e' key will do as it is suppost to.
Well, the crazy part is that the program somehow REMEMBERS that I've mapped the "ERROR" control to the 'e' key when I restart the program. Even more crazy is that if I now take the .exe to a different computer, it knows that 'e' is mapped to "ERROR" as well. Which doesn't make any since because the GUI in which you map keys is contained and is part of the program which responds to those mapped keys! HOW DOES IT REMEMBER? I can even re-compile the thing and it remembers.
W
T
F