コード例 #1
0
/**
 * Key bindings are found in config/keybindings.txt
 */
void InputState::loadKeyBindings() {

	FileParser infile;

	if (!infile.open(PATH_CONF + FILE_KEYBINDINGS, false, "")) {
		if (!infile.open("engine/default_keybindings.txt", true, "")) {
			saveKeyBindings();
			return;
		}
		else saveKeyBindings();
	}

	while (infile.next()) {
		int key1 = popFirstInt(infile.val);
		int key2 = popFirstInt(infile.val);

		// if we're loading an older keybindings file, convert greater than 0 mouse binds to negative
		if (key1 > 0 && key1 < 8) {
			key1 = (key1 + MOUSE_BIND_OFFSET) * (-1);
		}
		if (key2 > 0 && key2 < 8) {
			key2 = (key2 + MOUSE_BIND_OFFSET) * (-1);
		}

		// if we're loading an older keybindings file, we need to unbind all joystick bindings
		int key3 = -1;
		std::string temp = infile.val;
		if (popFirstString(temp) != "") {
			key3 = popFirstInt(infile.val);
		}

		int cursor = -1;

		if (infile.key == "cancel") cursor = CANCEL;
		else if (infile.key == "accept") cursor = ACCEPT;
		else if (infile.key == "up") cursor = UP;
		else if (infile.key == "down") cursor = DOWN;
		else if (infile.key == "left") cursor = LEFT;
		else if (infile.key == "right") cursor = RIGHT;
		else if (infile.key == "bar1") cursor = BAR_1;
		else if (infile.key == "bar2") cursor = BAR_2;
		else if (infile.key == "bar3") cursor = BAR_3;
		else if (infile.key == "bar4") cursor = BAR_4;
		else if (infile.key == "bar5") cursor = BAR_5;
		else if (infile.key == "bar6") cursor = BAR_6;
		else if (infile.key == "bar7") cursor = BAR_7;
		else if (infile.key == "bar8") cursor = BAR_8;
		else if (infile.key == "bar9") cursor = BAR_9;
		else if (infile.key == "bar0") cursor = BAR_0;
		else if (infile.key == "main1") cursor = MAIN1;
		else if (infile.key == "main2") cursor = MAIN2;
		else if (infile.key == "character") cursor = CHARACTER;
		else if (infile.key == "inventory") cursor = INVENTORY;
		else if (infile.key == "powers") cursor = POWERS;
		else if (infile.key == "log") cursor = LOG;
		else if (infile.key == "ctrl") cursor = CTRL;
		else if (infile.key == "shift") cursor = SHIFT;
		else if (infile.key == "alt") cursor = ALT;
		else if (infile.key == "delete") cursor = DEL;
		else if (infile.key == "actionbar") cursor = ACTIONBAR;
		else if (infile.key == "actionbar_back") cursor = ACTIONBAR_BACK;
		else if (infile.key == "actionbar_forward") cursor = ACTIONBAR_FORWARD;
		else if (infile.key == "actionbar_use") cursor = ACTIONBAR_USE;
		else if (infile.key == "developer_menu") cursor = DEVELOPER_MENU;

		if (cursor != -1) {
			binding[cursor] = key1;
			binding_alt[cursor] = key2;
			binding_joy[cursor] = key3;
		}

	}
	infile.close();
}
コード例 #2
0
ファイル: keybindings.cpp プロジェクト: TonyAlloa/miranda-dev
BOOL CALLBACK DlgProcKeyBindingsOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{

	switch (msg) {
	case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			OldEditProc = (WNDPROC) SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_PREVIEW), GWLP_WNDPROC, (LONG_PTR) KeyBindingsEditProc);
			currentTreeItem = NULL;
			loadTempKeyBindings();
			buildTree(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));
			EnableWindow(GetDlgItem(hwndDlg, IDC_ADD), FALSE);
			EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE);
		}
		return TRUE;
	case WM_KEYDOWN:
	case WM_SYSKEYDOWN:
		SendDlgItemMessage(hwndDlg, IDC_PREVIEW, msg, wParam, lParam);
		return TRUE;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_ADD:
			if (currentTreeItem->keyBinding != NULL) {
				int i;
				removeTempKeyBinding(currentTreeItem->keyBinding->actionGroupName, modifiers | virtualKey);
				for (i=0; i<5; i++) {
					if (currentTreeItem->keyBinding->tempKey[i] == 0) {
						currentTreeItem->keyBinding->tempKey[i] = modifiers | virtualKey;
						break;
					}
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_DELETE:
			if (currentTreeItem->keyBinding != NULL) {
				int index = SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETCURSEL, 0, 0);
				if (index != LB_ERR && index <5) {
					if (currentTreeItem->keyBinding->tempKey[index] != 0) {
						int i;
						for (i = index + 1; i < 5; i++) {
							currentTreeItem->keyBinding->tempKey[i-1] = currentTreeItem->keyBinding->tempKey[i];
						}
						currentTreeItem->keyBinding->tempKey[4] = 0;
					}
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_BTN_RESET:
			if (currentTreeItem->keyBinding != NULL) {
				int i;
				for (i = 0; i < 5; i++) {
					removeTempKeyBinding(currentTreeItem->keyBinding->actionGroupName, currentTreeItem->keyBinding->defaultKey[i]);
					currentTreeItem->keyBinding->tempKey[i] = currentTreeItem->keyBinding->defaultKey[i];
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_BTN_UNDO:
			if (currentTreeItem->keyBinding != NULL) {
				int i;
				for (i = 0; i < 5; i++) {
					removeTempKeyBinding(currentTreeItem->keyBinding->actionGroupName, currentTreeItem->keyBinding->key[i]);
					currentTreeItem->keyBinding->tempKey[i] = currentTreeItem->keyBinding->key[i];
				}
			}
			refreshListBox(hwndDlg);
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;
		case IDC_LIST:
			if (HIWORD(wParam) == LBN_SELCHANGE) {
				EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE);
			}
			break;
		}
		break;
	case WM_NOTIFY:
		if (((LPNMHDR) lParam)->idFrom == IDC_CATEGORYLIST)
		{
			switch(((NMHDR*)lParam)->code) {
			case TVN_SELCHANGEDA:
			case TVN_SELCHANGEDW:
				{
					TVITEM tvi = {0};
					tvi.hItem = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));
					tvi.mask = TVIF_HANDLE|TVIF_PARAM;
					TreeView_GetItem(GetDlgItem(hwndDlg, IDC_CATEGORYLIST), &tvi);
					currentTreeItem = (TreeItem *) tvi.lParam;
					refreshListBox(hwndDlg);
					break;
				}
			case TVN_DELETEITEMA:
			case TVN_DELETEITEMW:
				{
					TreeItem *treeItem = (TreeItem *)(((LPNMTREEVIEW)lParam)->itemOld.lParam);
					if (treeItem) {
						mir_free(treeItem->paramName);
						mir_free(treeItem);
					}
					break;
				}
			}
		}
		if (((LPNMHDR) lParam)->idFrom == 0 && ((LPNMHDR) lParam)->code == PSN_APPLY ) {
			saveKeyBindings();
		}
		break;
	case WM_DESTROY:
		saveCollapseState(GetDlgItem(hwndDlg, IDC_CATEGORYLIST));

	}
	return FALSE;
}