Fixed WXKeyToString which had several problems, mostly just to get

hotkey configuration working with wx 2.9, but it turned out to be
too tempting to use it to hack up OS X keyboard support using wx
key events in the "old" input plugins.

It was with some reluctance that I used PAD_Input (and copied it
for Wiimote as well) as that is clearly a deprecated interface,
but this way the hack is contained within the old plugins for when
the switchover to ControllerInterface happens.

The idea is to provide stable keyboard support on OS X for both
GCPad and Wiimote while we debug HID keyboard and real 'mote code.

It works pretty well, although the wx approach does impose a few
limitations like no arrow keys and left/right side modifier keys
are considered equivalent.


git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5622 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Soren Jorvang
2010-06-05 19:03:37 +00:00
parent 7d0f03cb61
commit 5c335a8c85
23 changed files with 364 additions and 156 deletions
+26 -27
View File
@@ -34,6 +34,7 @@
#include "Config.h"
#include "GCPad.h"
#include "FileUtil.h"
#include "WXInputBase.h"
static const char* gcControlNames[] =
{
@@ -122,34 +123,32 @@ static const int gcDefaultControls[] =
0x00, // L semi-press
0x00, // R semi-press
};
#elif defined(__APPLE__)
// Reference for Cocoa key codes:
// http://boredzo.org/blog/archives/2007-05-22/virtual-key-codes
#else defined(USE_WX) && USE_WX
{
7, // A (x)
6, // B (z)
8, // X (c)
1, // Y (s)
2, // Z (d)
36, // Start (return)
17, // D-pad up (t)
5, // D-pad down (g)
3, // D-pad left (f)
4, // D-pad right (h)
126, // Main stick up (up)
125, // Main stick down (down)
123, // Main stick left (left)
124, // Main stick right (right)
56, // Main stick semi (left shift)
34, // C-stick up (i)
40, // C-stick down (k)
38, // C-stick left (j)
37, // C-stick right (l)
59, // C-stick semi (left control)
12, // L (q)
13, // R (w)
-1, // L semi-press (none)
-1, // R semi-press (none)
'X', // A
'Z', // B
'C', // X
'S', // Y
'D', // Z
WXK_RETURN, // Start
'T', // D-pad up
'G', // D-pad down
'F', // D-pad left
'H', // D-pad right
WXK_UP, // Main stick up
WXK_DOWN, // Main stick down
WXK_LEFT, // Main stick left
WXK_RIGHT, // Main stick right
WXK_SHIFT, // Main stick semi
'I', // C-stick up
'K', // C-stick down
'J', // C-stick left
'L', // C-stick right
WXK_CONTROL, // C-stick semi
'Q', // L
'W', // R
0, // L semi-press
0, // R semi-press
};
#endif
@@ -28,6 +28,7 @@
#include "math.h" // System
#include "WXInputBase.h"
#include "ConfigBox.h"
#include "Config.h"
#include "GCPad.h"
@@ -239,6 +240,10 @@ void GCPadConfigDialog::OnKeyDown(wxKeyEvent& event)
SetButtonText(ClickedButton->GetId(),
wxString::FromAscii(keyStr));
SaveButtonMapping(ClickedButton->GetId(), XKey);
#elif defined(USE_WX) && USE_WX
SetButtonText(ClickedButton->GetId(),
InputCommon::WXKeyToString(g_Pressed));
SaveButtonMapping(ClickedButton->GetId(), g_Pressed);
#endif
}
EndGetButtons();
@@ -394,6 +399,13 @@ void GCPadConfigDialog::UpdateGUI()
InputCommon::XKeyToString(GCMapping[m_Page].Button[x + EGC_A], keyStr);
m_Button_GC[x][m_Page]->SetLabel(wxString::FromAscii(keyStr));
}
#elif defined(USE_WX) && USE_WX
for (int x = 0; x <= IDB_SHDR_SEMI_R - IDB_BTN_A; x++)
{
m_Button_GC[x][m_Page]-> \
SetLabel(InputCommon::WXKeyToString(
GCMapping[m_Page].Button[x + EGC_A]));
}
#endif
DoChangeDeadZone();
+17
View File
@@ -243,10 +243,19 @@ void EmuStateChange(PLUGIN_EMUSTATE newState)
{
}
// Hack to use wx key events
volatile bool wxkeystate[256];
// Set buttons status from keyboard input. Currently this is done from wxWidgets in the main application.
// --------------
void PAD_Input(u16 _Key, u8 _UpDown)
{
#if defined(__APPLE__) && defined(USE_WX) && USE_WX
if (_Key < 256)
{
wxkeystate[_Key] = _UpDown;
}
#endif
}
// Set PAD status
@@ -624,6 +633,11 @@ bool IsKey(int Key)
Ret = (keys[keyCode/8] & (1 << (keyCode%8))); // Keyboard (Linux)
}
else if (MapKey < 0x1100)
#elif defined (USE_WX) && USE_WX
if (MapKey < 256) {
Ret = wxkeystate[MapKey];
}
else if (MapKey < 0x1100)
#else
if (MapKey < 0x1100)
#endif
@@ -647,5 +661,8 @@ bool IsKey(int Key)
// ----------------
bool IsFocus()
{
#if defined(__APPLE__) && defined(USE_WX) && USE_WX
return true; /* XXX */
#endif
return g_PADInitialize->pRendererHasFocus();
}
-3
View File
@@ -42,9 +42,6 @@
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
//no need for Cocoa yet, but I guess ayuanx isn't done yet.
//#elif defined(__APPLE__)
// #include <Cocoa/Cocoa.h>
#endif
#include "pluginspecs_pad.h"
@@ -26,6 +26,7 @@
#include "EmuDefinitions.h" // for PadMapping
#include "main.h"
#include "FileUtil.h"
#include "WXInputBase.h"
// Configuration file control names
// Do not change the order unless you change the related arrays
@@ -139,6 +140,23 @@ static int wmDefaultControls[] =
XK_comma,
XK_period,
XK_slash,
#elif defined(USE_WX) && USE_WX
'Z',
'X',
'C',
'V',
'P',
'O',
WXK_BACK,
WXK_LEFT,
WXK_RIGHT,
WXK_UP,
WXK_DOWN,
'N',
'M',
WXK_SEPARATOR,
WXK_DECIMAL,
WXK_DIVIDE,
#else
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
#endif
@@ -168,6 +186,18 @@ static int wmDefaultControls[] =
XK_KP_1,
XK_KP_3,
XK_KP_2,
#elif defined(USE_WX) && USE_WX
WXK_NUMPAD0,
WXK_NUMPAD_DECIMAL,
WXK_NUMPAD4,
WXK_NUMPAD6,
WXK_NUMPAD8,
WXK_NUMPAD5,
WXK_NUMPAD7,
WXK_NUMPAD9,
WXK_NUMPAD1,
WXK_NUMPAD3,
WXK_NUMPAD2,
#else
0,0,0,0,0,0,0,0,0,0,0,
#endif
@@ -184,6 +214,11 @@ static int wmDefaultControls[] =
XK_bracketright,
XK_semicolon,
XK_quoteright,
#elif defined(USE_WX) && USE_WX
'O',
'P',
'K',
'L',
#else
0,0,0,0,
#endif
@@ -207,6 +242,11 @@ static int wmDefaultControls[] =
XK_KP_6,
XK_KP_8,
XK_KP_5,
#elif defined(HAVE_X11) && HAVE_X11
WXK_NUMPAD4,
WXK_NUMPAD6,
WXK_NUMPAD8,
WXK_NUMPAD5,
#else
0,0,0,0,
#endif
@@ -240,6 +280,11 @@ static int wmDefaultControls[] =
XK_KP_6,
XK_KP_8,
XK_KP_5,
#elif defined(HAVE_X11) && HAVE_X11
WXK_NUMPAD4,
WXK_NUMPAD6,
WXK_NUMPAD8,
WXK_NUMPAD5,
#else
0,0,0,0,
#endif
@@ -18,6 +18,7 @@
#include "wiimote_real.h" // for MAX_WIIMOTES
#include "wiimote_hid.h"
#include "main.h"
#include "WXInputBase.h"
#include "ConfigPadDlg.h"
#include "ConfigBasicDlg.h"
#include "Config.h"
@@ -241,6 +242,10 @@ void WiimotePadConfigDialog::OnKeyDown(wxKeyEvent& event)
SetButtonText(ClickedButton->GetId(),
wxString::FromAscii(keyStr));
SaveButtonMapping(ClickedButton->GetId(), XKey);
#elif defined(USE_WX) && USE_WX
SetButtonText(ClickedButton->GetId(),
InputCommon::WXKeyToString(g_Pressed));
SaveButtonMapping(ClickedButton->GetId(), g_Pressed);
#endif
}
EndGetButtons();
@@ -1133,6 +1138,61 @@ void WiimotePadConfigDialog::UpdateGUI()
m_Button_GH3[x][m_Page]->SetLabel(wxString::FromAscii(keyStr));
}
}
#elif defined(USE_WX) && USE_WX
for (int x = 0; x <= IDB_WM_SHAKE - IDB_WM_A; x++)
{
m_Button_Wiimote[x][m_Page]-> \
SetLabel(InputCommon::WXKeyToString(
WiiMoteEmu::WiiMapping[m_Page]. \
Button[x + WiiMoteEmu::EWM_A]));
}
if (WiiMoteEmu::WiiMapping[m_Page].iExtensionConnected ==
WiiMoteEmu::EXT_NUNCHUK)
{
m_NunchuckComboStick[m_Page]-> \
SetSelection(WiiMoteEmu::WiiMapping[m_Page].Stick.NC);
for (int x = 0; x <= IDB_NC_SHAKE - IDB_NC_Z; x++)
{
m_Button_NunChuck[x][m_Page]-> \
SetLabel(InputCommon::WXKeyToString(
WiiMoteEmu::WiiMapping[m_Page]. \
Button[x + WiiMoteEmu::ENC_Z]));
}
}
else if (WiiMoteEmu::WiiMapping[m_Page].iExtensionConnected ==
WiiMoteEmu::EXT_CLASSIC_CONTROLLER)
{
m_CcComboLeftStick[m_Page]-> \
SetSelection(WiiMoteEmu::WiiMapping[m_Page].Stick.CCL);
m_CcComboRightStick[m_Page]-> \
SetSelection(WiiMoteEmu::WiiMapping[m_Page].Stick.CCR);
m_CcComboTriggers[m_Page]-> \
SetSelection(WiiMoteEmu::WiiMapping[m_Page].Stick.CCT);
for (int x = 0; x <= IDB_CC_RD - IDB_CC_A; x++)
{
m_Button_Classic[x][m_Page]-> \
SetLabel(InputCommon::WXKeyToString(
WiiMoteEmu::WiiMapping[m_Page]. \
Button[x + WiiMoteEmu::ECC_A]));
}
}
else if(WiiMoteEmu::WiiMapping[m_Page].iExtensionConnected ==
WiiMoteEmu::EXT_GUITARHERO)
{
m_GH3ComboAnalog[m_Page]-> \
SetSelection(WiiMoteEmu::WiiMapping[m_Page].Stick.GH);
for (int x = 0; x <= IDB_GH3_STRUM_DOWN - IDB_GH3_GREEN; x++)
{
m_Button_GH3[x][m_Page]-> \
SetLabel(InputCommon::WXKeyToString(
WiiMoteEmu::WiiMapping[m_Page]. \
Button[x + WiiMoteEmu::EGH_Green]));
}
}
#endif
DoChangeDeadZone();
@@ -34,7 +34,7 @@
The Data Report's path from here is
WII_IPC_HLE_WiiMote.cpp:
Callback_WiimoteInput()
Callback_WiimoteInterruptChannel()
CWII_IPC_HLE_WiiMote::SendL2capData()
WII_IPC_HLE_Device_usb.cpp:
CWII_IPC_HLE_Device_usb_oh1_57e_305::SendACLPacket()
@@ -116,7 +116,7 @@ void SendReportCore(u16 _channelID)
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Debugging
//ReadDebugging(true, DataFrame, Offset);
}
@@ -141,7 +141,7 @@ void SendReportCoreAccel(u16 _channelID)
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Debugging
//ReadDebugging(true, DataFrame, Offset);
@@ -170,7 +170,7 @@ void SendReportCoreAccelIr12(u16 _channelID) {
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Debugging
//ReadDebugging(true, DataFrame, Offset);
@@ -215,7 +215,7 @@ void SendReportCoreAccelExt16(u16 _channelID)
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Debugging
//ReadDebugging(true, DataFrame, Offset);
@@ -290,7 +290,7 @@ void SendReportCoreAccelIr10Ext(u16 _channelID)
DEBUG_LOG(WIIMOTE, " Channel: %04x", _channelID);
DEBUG_LOG(WIIMOTE, " Size: %08x", Offset);
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Debugging
//ReadDebugging(true, DataFrame, Offset);
@@ -677,7 +677,7 @@ void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
HidOutputReport(_channelID, (wm_report*)hidp->data);
u8 handshake = HID_HANDSHAKE_SUCCESS;
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, &handshake, 1);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, &handshake, 1);
PanicAlert("HID_TYPE_DATA - OUTPUT: Ambiguous Control Channel Report!");
}
@@ -178,7 +178,7 @@ void WmSendAck(u16 _channelID, u8 _reportID)
DEBUG_LOG(WIIMOTE, "WMSendAck");
DEBUG_LOG(WIIMOTE, " Report ID: %02x", _reportID);
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Debugging
//ReadDebugging(true, DataFrame, Offset);
@@ -363,7 +363,7 @@ void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _AddressHI,
#endif
// Send a piece
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Update the size that is left
_Size -= copySize;
@@ -541,7 +541,7 @@ void WmRequestStatus(u16 _channelID, wm_request_status* rs, int Extension)
DEBUG_LOG(WIIMOTE, " LEDs: %x", pStatus->leds);
g_WiimoteInitialize.pWiimoteInput(g_ID, _channelID, DataFrame, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(g_ID, _channelID, DataFrame, Offset);
// Debugging
//ReadDebugging(true, DataFrame, Offset);
@@ -34,6 +34,9 @@
extern SWiimoteInitialize g_WiimoteInitialize;
// Hack to use wx key events
extern volatile bool wxkeystate[256];
namespace WiiMoteEmu
{
@@ -319,6 +322,11 @@ bool IsKey(int Key)
Ret = (keys[keyCode/8] & (1 << (keyCode%8))); // Keyboard (Linux)
}
else if (MapKey < 0x1100)
#elif defined (USE_WX) && USE_WX
if (MapKey < 256) {
Ret = wxkeystate[MapKey];
}
else if (MapKey < 0x1100)
#else
if (MapKey < 0x1100)
#endif
@@ -294,6 +294,21 @@ void EmuStateChange(PLUGIN_EMUSTATE newState)
g_EmulatorState = newState;
}
// Hack to use wx key events
volatile bool wxkeystate[256];
// Set buttons status from keyboard input. Currently this is done from
// wxWidgets in the main application.
// --------------
void Wiimote_Input(u16 _Key, u8 _UpDown)
{
#if defined(__APPLE__) && defined(USE_WX) && USE_WX
if (_Key < 256)
{
wxkeystate[_Key] = _UpDown;
}
#endif
}
/* This function produce Wiimote Input (reports from the Wiimote) in response
to Output from the Wii. It's called from WII_IPC_HLE_WiiMote.cpp.
@@ -415,6 +430,9 @@ unsigned int Wiimote_GetAttachedControllers()
bool IsFocus()
{
#if defined(__APPLE__) && defined(USE_WX) && USE_WX
return true; /* XXX */
#endif
return g_WiimoteInitialize.pRendererHasFocus();
}
@@ -281,7 +281,7 @@ void SendEvent(SEvent& _rEvent)
Offset += sizeof(_rEvent.m_PayLoad);
// Send it
g_WiimoteInitialize.pWiimoteInput(m_WiimoteNumber, m_channelID, Buffer, Offset);
g_WiimoteInitialize.pWiimoteInterruptChannel(m_WiimoteNumber, m_channelID, Buffer, Offset);
// Debugging
// ReadDebugging(false, Buffer, Offset);
@@ -195,7 +195,7 @@ void Wiimote::SendAck(const u16 _channelID, u8 _reportID)
ack->reportID = _reportID;
ack->errorID = 0;
g_WiimoteInitialize.pWiimoteInput( m_index, _channelID, data, sizeof(data));
g_WiimoteInitialize.pWiimoteInterruptChannel( m_index, _channelID, data, sizeof(data));
}
// old comment
@@ -234,7 +234,7 @@ void Wiimote::RequestStatus(const u16 _channelID, wm_request_status* rs)
*(wm_status_report*)(data + 2) = m_status;
// send report
g_WiimoteInitialize.pWiimoteInput(m_index, _channelID, data, sizeof(data));
g_WiimoteInitialize.pWiimoteInterruptChannel(m_index, _channelID, data, sizeof(data));
}
/* Write data to Wiimote and Extensions registers. */
@@ -487,7 +487,7 @@ void Wiimote::SendReadDataReply(const u16 _channelID, ReadRequest& _request)
}
// Send a piece
g_WiimoteInitialize.pWiimoteInput(m_index, _channelID, data, sizeof(data));
g_WiimoteInitialize.pWiimoteInterruptChannel(m_index, _channelID, data, sizeof(data));
}
void Wiimote::DoState(PointerWrap& p)
@@ -589,7 +589,7 @@ void Wiimote::Update()
}
}
// send data report
g_WiimoteInitialize.pWiimoteInput( m_index, m_reporting_channel, data, rpt.size );
g_WiimoteInitialize.pWiimoteInterruptChannel( m_index, m_reporting_channel, data, rpt.size );
}
void Wiimote::ControlChannel(const u16 _channelID, const void* _pData, u32 _Size)
@@ -628,7 +628,7 @@ void Wiimote::ControlChannel(const u16 _channelID, const void* _pData, u32 _Size
HidOutputReport(_channelID, (wm_report*)hidp->data);
u8 handshake = HID_HANDSHAKE_SUCCESS;
g_WiimoteInitialize.pWiimoteInput(m_index, _channelID, &handshake, 1);
g_WiimoteInitialize.pWiimoteInterruptChannel(m_index, _channelID, &handshake, 1);
PanicAlert("HID_TYPE_DATA - OUTPUT: Ambiguous Control Channel Report!");
}
@@ -144,7 +144,18 @@ void Wiimote_ControlChannel(int _number, u16 _channelID, const void* _pData, u32
}
// __________________________________________________________________________________________________
// Function: Wiimote_Input
// Function: Send keyboard input to the plugin
// Purpose:
// input: The key and if it's pressed or released
// output: None
//
void Wiimote_Input(u16 _Key, u8 _UpDown)
{
return;
}
// __________________________________________________________________________________________________
// Function: Wiimote_InterruptChannel
// Purpose: An L2CAP packet is passed from the Core to the Wiimote,
// on the HID INTERRUPT channel.
// input: Da pakket.