Angband.oook.cz
Angband.oook.cz
AboutDownloadVariantsLadderForumCompetitionSpoilersComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old May 24, 2012, 10:54   #1
PowerWyrm
Knight
 
PowerWyrm's Avatar
 
Join Date: Apr 2008
Posts: 726
PowerWyrm is on a distinguished road
Fixing dir, shift-dir and ctrl-dir keys part 1: Win client

The problem: shift-dir and ctrl-dir keys (keypad) don't work with numlock on

The solution (main-win.c):

Code:
static bool handle_keydown(WPARAM wParam, LPARAM lParam)
{
	keycode_t ch = 0;

	bool kp = FALSE;
	
	int mods = 0;
	static bool has_shift = FALSE;
	static bool has_ctrl = FALSE;
	
#define check_ctrl(K) \
    if (has_ctrl) \
    { \
        ch = (K); \
        mods |= KC_MOD_CONTROL; \
    }

#ifdef USE_SAVER
	if (screensaver_active)
	{
		stop_screensaver();
		return TRUE;
	}
#endif /* USE_SAVER */

	/* for VK_ http://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx */
	switch (wParam) {
		case VK_F1: ch = KC_F1; break;
		case VK_F2: ch = KC_F2; break;
		case VK_F3: ch = KC_F3; break;
		case VK_F4: ch = KC_F4; break;
		case VK_F5: ch = KC_F5; break;
		case VK_F6: ch = KC_F6; break;
		case VK_F7: ch = KC_F7; break;
		case VK_F8: ch = KC_F8; break;
		case VK_F9: ch = KC_F9; break;
		case VK_F10: ch = KC_F10; break;
		case VK_F11: ch = KC_F11; break;
		case VK_F12: ch = KC_F12; break;
		case VK_F13: ch = KC_F13; break;
		case VK_F14: ch = KC_F14; break;
		case VK_F15: ch = KC_F15; break;

		case VK_INSERT: ch = KC_INSERT; break;
		case VK_DELETE: ch = KC_DELETE; break;
		/* Backspace is calling both backspace and delete
		   Removed the backspace call, so it only calls delete */
		case VK_BACK: break;
		/* Tab is registering as ^i; don't read it here*/
	        case VK_TAB: break;
		
        /* Ensure that shift-dir works with NUMLOCK on */
        case VK_PRIOR: ch = KC_PGUP; if (has_shift) mods |= KC_MOD_SHIFT; break;
		case VK_NEXT: ch = KC_PGDOWN; if (has_shift) mods |= KC_MOD_SHIFT; break;
		case VK_END: ch = KC_END; if (has_shift) mods |= KC_MOD_SHIFT; break;
		case VK_HOME: ch = KC_HOME; if (has_shift) mods |= KC_MOD_SHIFT; break;
		case VK_LEFT: ch = ARROW_LEFT; if (has_shift) mods |= KC_MOD_SHIFT; break;
		case VK_RIGHT: ch = ARROW_RIGHT; if (has_shift) mods |= KC_MOD_SHIFT; break;
		case VK_UP: ch = ARROW_UP; if (has_shift) mods |= KC_MOD_SHIFT; break;
		case VK_DOWN: ch = ARROW_DOWN; if (has_shift) mods |= KC_MOD_SHIFT; break;

		case VK_CLEAR: ch = '5'; kp=TRUE; break;
		case VK_PAUSE: ch = KC_PAUSE; break;
		
		case VK_SHIFT: has_shift = TRUE; return TRUE;
		case VK_CONTROL: has_ctrl = TRUE; return TRUE;
		
		/* Ensure that ctrl-dir works with NUMLOCK on */
		case VK_NUMPAD9:
            check_ctrl(KC_PGUP)
            break;
        case VK_NUMPAD3:
            check_ctrl(KC_PGDOWN)
            break;
        case VK_NUMPAD1:
            check_ctrl(KC_END)
            break;
        case VK_NUMPAD7:
            check_ctrl(KC_HOME)
            break;
        case VK_NUMPAD4:
            check_ctrl(ARROW_LEFT)
            break;
        case VK_NUMPAD6:
            check_ctrl(ARROW_RIGHT)
            break;
        case VK_NUMPAD8:
            check_ctrl(ARROW_UP)
            break;
        case VK_NUMPAD2:
            check_ctrl(ARROW_DOWN)
            break;
	}
	
	has_shift = FALSE;
	has_ctrl = FALSE;

	/* we could fall back on using the scancode */
	/* obtained using LOBYTE(HIWORD(lParam)) */
	/* see http://source.winehq.org/source/include/dinput.h#L468 */

	if (ch) {
		mods |= extract_modifiers(ch, kp);
		/* printf("ch=%d mods=%d\n", ch, mods); */
		/* fflush(stdout); */
		Term_keypress(ch, mods);
		return FALSE;
	}
	return TRUE;
}
This works with Win7 and an AZERTY keyboard (my tests didn't show any regression when I tried different combinations of keys). More tests with different configurations will be needed, but I think this fixes the problem once and for all.
__________________
PWMAngband variant maintainer - check http://www.mangband.org/forum/viewforum.php?f=9 to learn more about this new variant!
PowerWyrm is offline   Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[3.4-dev] Minor bugs with Win client PowerWyrm Development 0 April 18, 2012 13:17
Bug report: Can shift-run over the edge of the trap detection zone Remuz Development 26 July 13, 2011 23:26
can I bind macro to shift+numpad keys? fbas Vanilla 3 December 1, 2010 14:59
Play FAangband part II Fendell Orcbane AAR 6 November 29, 2010 20:53
Quill, Part II Sirridan AAR 9 June 25, 2009 03:51


All times are GMT +1. The time now is 08:33.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.