Esempio n. 1
0
// TODO: This is such a mess...
void UpdateNativeMenuKeys() {
	std::vector<KeyDef> confirmKeys, cancelKeys;
	std::vector<KeyDef> tabLeft, tabRight;
	std::vector<KeyDef> upKeys, downKeys, leftKeys, rightKeys;

	int confirmKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CROSS : CTRL_CIRCLE;
	int cancelKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CIRCLE : CTRL_CROSS;

	KeyFromPspButton(confirmKey, &confirmKeys);
	KeyFromPspButton(cancelKey, &cancelKeys);
	KeyFromPspButton(CTRL_LTRIGGER, &tabLeft);
	KeyFromPspButton(CTRL_RTRIGGER, &tabRight);
	KeyFromPspButton(CTRL_UP, &upKeys);
	KeyFromPspButton(CTRL_DOWN, &downKeys);
	KeyFromPspButton(CTRL_LEFT, &leftKeys);
	KeyFromPspButton(CTRL_RIGHT, &rightKeys);

#ifdef ANDROID
	// Hardcode DPAD on Android
	upKeys.push_back(KeyDef(DEVICE_ID_ANY, NKCODE_DPAD_UP));
	downKeys.push_back(KeyDef(DEVICE_ID_ANY, NKCODE_DPAD_DOWN));
	leftKeys.push_back(KeyDef(DEVICE_ID_ANY, NKCODE_DPAD_LEFT));
	rightKeys.push_back(KeyDef(DEVICE_ID_ANY, NKCODE_DPAD_RIGHT));
#endif

	// Push several hard-coded keys before submitting to native.
	const KeyDef hardcodedConfirmKeys[] = {
		KeyDef(DEVICE_ID_KEYBOARD, NKCODE_SPACE),
		KeyDef(DEVICE_ID_KEYBOARD, NKCODE_ENTER),
		KeyDef(DEVICE_ID_ANY, NKCODE_BUTTON_A),
	};

	// If they're not already bound, add them in.
	for (size_t i = 0; i < ARRAY_SIZE(hardcodedConfirmKeys); i++) {
		if (std::find(confirmKeys.begin(), confirmKeys.end(), hardcodedConfirmKeys[i]) == confirmKeys.end())
			confirmKeys.push_back(hardcodedConfirmKeys[i]);
	}

	const KeyDef hardcodedCancelKeys[] = {
		KeyDef(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE),
		KeyDef(DEVICE_ID_ANY, NKCODE_BACK),
		KeyDef(DEVICE_ID_ANY, NKCODE_BUTTON_B),
	};

	for (size_t i = 0; i < ARRAY_SIZE(hardcodedCancelKeys); i++) {
		if (std::find(cancelKeys.begin(), cancelKeys.end(), hardcodedCancelKeys[i]) == cancelKeys.end())
			cancelKeys.push_back(hardcodedCancelKeys[i]);
	}

	SetDPadKeys(upKeys, downKeys, leftKeys, rightKeys);
	SetConfirmCancelKeys(confirmKeys, cancelKeys);
	SetTabLeftRightKeys(tabLeft, tabRight);
}
Esempio n. 2
0
void AutoConfForPad(const std::string &name) {
	ILOG("Autoconfiguring pad for %s", name.c_str());
	if (name == "Xbox 360 Pad") {
		SetDefaultKeyMap(DEFAULT_MAPPING_X360, true);
	} else {
		SetDefaultKeyMap(DEFAULT_MAPPING_PAD, true);
	}

#ifndef MOBILE_DEVICE
	// Add a couple of convenient keyboard mappings by default, too.
	g_controllerMap[VIRTKEY_PAUSE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE));
	g_controllerMap[VIRTKEY_UNTHROTTLE].push_back(KeyDef(DEVICE_ID_KEYBOARD, NKCODE_TAB));
#endif
}
Esempio n. 3
0
// TODO: Make the ini format nicer.
void LoadFromIni(IniFile &file) {
	RestoreDefault();
	if (!file.HasSection("ControlMapping")) {
		return;
	}

	IniFile::Section *controls = file.GetOrCreateSection("ControlMapping");
	for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
		std::string value;
		controls->Get(psp_button_names[i].name.c_str(), &value, "");

		// Erase default mapping
		g_controllerMap.erase(psp_button_names[i].key);
		if (value.empty()) 
			continue;

		std::vector<std::string> mappings;
		SplitString(value, ',', mappings);

		for (size_t j = 0; j < mappings.size(); j++) {
			std::vector<std::string> parts;
			SplitString(mappings[j], '-', parts);
			int deviceId = atoi(parts[0].c_str());
			int keyCode = atoi(parts[1].c_str());

			SetKeyMapping(psp_button_names[i].key, KeyDef(deviceId, keyCode), false);
		}
	}

	UpdateConfirmCancelKeys();
}
Esempio n. 4
0
static void SetDefaultKeyMap(int deviceId, const DefMappingStruct *array, size_t count, bool replace) {
	for (size_t i = 0; i < count; i++) {
		if (array[i].direction == 0)
			SetKeyMapping(array[i].pspKey, KeyDef(deviceId, array[i].key), replace);
		else
			SetAxisMapping(array[i].pspKey, deviceId, array[i].key, array[i].direction, replace);
	}
}
Esempio n. 5
0
static bool FindKeyMapping(int deviceId, int key, std::vector<int> *psp_button) {
	// Brute force, let's optimize later
	for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
		for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
			if (*iter2 == KeyDef(deviceId, key)) {
				psp_button->push_back(iter->first);
			}
		}
	}
	return psp_button->size() > 0;
}
Esempio n. 6
0
static bool FindKeyMapping(int deviceId, int key, int *psp_button) {
	// Brute force, let's optimize later
	for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
		for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
			if (*iter2 == KeyDef(deviceId, key)) {
				*psp_button = iter->first;
				return true;
			}
		}
	}
	return false;
}
Esempio n. 7
0
void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace) {
	int key = TranslateKeyCodeFromAxis(axisId, direction);
	SetKeyMapping(btn, KeyDef(deviceId, key), replace);
}
Esempio n. 8
0
KeyDef AxisDef(int deviceId, int axisId, int direction) {
	return KeyDef(deviceId, TranslateKeyCodeFromAxis(axisId, direction));
}
Esempio n. 9
0
File: view.cpp Progetto: kg/ppsspp
static bool MatchesKeyDef(const std::vector<KeyDef> &defs, const KeyInput &key) {
	// In addition to the actual search, we need to do another search where we replace the device ID with "ANY".
	return
		std::find(defs.begin(), defs.end(), KeyDef(key.deviceId, key.keyCode)) != defs.end() ||
		std::find(defs.begin(), defs.end(), KeyDef(DEVICE_ID_ANY, key.keyCode)) != defs.end();
}