Date: Mon, 13 Oct 2003 13:37:18 +0100
authorSam Lantinga <slouken@libsdl.org>
Wed, 05 Nov 2003 23:11:05 +0000
changeset 7339557ac1857a3
parent 732 d18e2b224d0e
child 734 0310bb01091f
Date: Mon, 13 Oct 2003 13:37:18 +0100
From: "alan buckley"
Subject: Modification for RISC OS SDL port (SDL_riscosevents.c)

This modification improves the key press to Unicode character translation.
src/video/riscos/SDL_riscosevents.c
     1.1 --- a/src/video/riscos/SDL_riscosevents.c	Wed Nov 05 21:07:29 2003 +0000
     1.2 +++ b/src/video/riscos/SDL_riscosevents.c	Wed Nov 05 23:11:05 2003 +0000
     1.3 @@ -71,7 +71,6 @@
     1.4  
     1.5  static SDL_keysym *TranslateKey(int intkey, SDL_keysym *keysym, int pressed);
     1.6  
     1.7 -
     1.8  void RISCOS_PollMouse(_THIS);
     1.9  void RISCOS_PollKeyboard();
    1.10  
    1.11 @@ -144,7 +143,7 @@
    1.12    RO_keymap[53] = SDLK_u;
    1.13    RO_keymap[54] = SDLK_o;
    1.14    RO_keymap[55] = SDLK_p;
    1.15 -  RO_keymap[56] = SDLK_LEFTPAREN;
    1.16 +  RO_keymap[56] = SDLK_LEFTBRACKET;
    1.17    RO_keymap[57] = SDLK_UP;
    1.18    RO_keymap[58] = SDLK_KP_PLUS;
    1.19    RO_keymap[59] = SDLK_KP_MINUS;
    1.20 @@ -173,7 +172,7 @@
    1.21    RO_keymap[85] = SDLK_n;
    1.22    RO_keymap[86] = SDLK_l;
    1.23    RO_keymap[87] = SDLK_SEMICOLON;
    1.24 -  RO_keymap[88] = SDLK_RIGHTPAREN;
    1.25 +  RO_keymap[88] = SDLK_RIGHTBRACKET;
    1.26    RO_keymap[89] = SDLK_DELETE;
    1.27    RO_keymap[90] = SDLK_KP_MINUS;
    1.28    RO_keymap[91] = SDLK_KP_MULTIPLY;
    1.29 @@ -356,7 +355,7 @@
    1.30  	{
    1.31  		which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF);
    1.32  	    if (which_key != ROKEY_NONE)
    1.33 -		{
    1.34 +	    {
    1.35  		    switch(which_key)
    1.36  		    {
    1.37  		    /* Skip over mouse keys */
    1.38 @@ -370,6 +369,10 @@
    1.39  			case 71: case 24: case 87: case 40:
    1.40  			    break;
    1.41  
    1.42 +            /* Ignore break as it can be latched on */
    1.43 +            case 44:
    1.44 +                break;
    1.45 +
    1.46  			default:
    1.47  				RO_pressed[which_key] += 2;
    1.48  				break;
    1.49 @@ -426,11 +429,11 @@
    1.50  
    1.51  		state = (_kernel_osbyte(202, 0, 255) & 0xFF);
    1.52  
    1.53 -		/*TODO: better key to char mapping */
    1.54 +		/*TODO: Take into account other keyboard layouts */
    1.55  
    1.56 -		ch = keysym->sym; /* This should handle most keys */
    1.57 +		ch = keysym->sym; /* This should handle most unshifted keys */
    1.58  
    1.59 -        if (intkey < 9)
    1.60 +        if (intkey < 9 || ch == SDLK_UNKNOWN)
    1.61          {
    1.62             ch = 0;
    1.63  
    1.64 @@ -438,15 +441,95 @@
    1.65  		{
    1.66  			ch = ch & 31;
    1.67  
    1.68 -		} else if ((state & 16) == 0) /* Caps lock is on */
    1.69 +		} else 
    1.70  		{
    1.71 -			if ((state & 128) == 0) /* Shift Enable off */
    1.72 +			int topOfKey = 0;
    1.73 +            if (state & 8) /* Shift on */
    1.74  			{
    1.75 -				ch = toupper(ch);
    1.76 +				topOfKey = 1;
    1.77  			}
    1.78 -		} else if (state & 8) /* Shift on */
    1.79 -		{
    1.80 -			ch = toupper(ch);
    1.81 +
    1.82 +			if ((state & 16) == 0) /* Caps lock is on */
    1.83 +			{
    1.84 +			   if (ch >= SDLK_a && ch <= SDLK_z)
    1.85 +			   {
    1.86 + 				  if ((state & 128) == 0) /* Shift Enable off */
    1.87 +				  {
    1.88 +				     /* All letter become upper case */
    1.89 +				 	 topOfKey = 1;
    1.90 +				  } else
    1.91 +				  {
    1.92 +				     /* Shift+Letters gives lower case */
    1.93 +				     topOfKey = 1 - topOfKey;
    1.94 +				  }
    1.95 +		       }
    1.96 +			}
    1.97 +
    1.98 +			if (topOfKey)
    1.99 +			{
   1.100 +				/* Key produced with shift held down */
   1.101 +
   1.102 +				/* Letters just give upper case version */
   1.103 +				if (ch >= SDLK_a && ch <= SDLK_z) ch = toupper(ch);
   1.104 +				else
   1.105 +				{
   1.106 +					switch(ch)
   1.107 +					{
   1.108 +					case SDLK_HASH:   ch = '~'; break;
   1.109 +					case SDLK_QUOTE:  ch = '@'; break;
   1.110 +					case SDLK_COMMA:  ch = '<'; break;
   1.111 +					case SDLK_MINUS:  ch = '_'; break;
   1.112 +					case SDLK_PERIOD: ch = '>'; break;
   1.113 +					case SDLK_SLASH:  ch = '?'; break;
   1.114 +
   1.115 +					case SDLK_0: ch = ')'; break;
   1.116 +					case SDLK_1: ch = '!'; break;
   1.117 +					case SDLK_2: ch = '"'; break;
   1.118 +					case SDLK_3: ch = ''; break;
   1.119 +					case SDLK_4: ch = '$'; break;
   1.120 +					case SDLK_5: ch = '%'; break;
   1.121 +					case SDLK_6: ch = '^'; break;
   1.122 +					case SDLK_7: ch = '&'; break;
   1.123 +					case SDLK_8: ch = '*'; break;
   1.124 +					case SDLK_9: ch = '('; break;
   1.125 +
   1.126 +					case SDLK_SEMICOLON:    ch = ':'; break;
   1.127 +					case SDLK_EQUALS:       ch = '+'; break;
   1.128 +					case SDLK_LEFTBRACKET:  ch = '{'; break;
   1.129 +					case SDLK_BACKSLASH:    ch = '|'; break;
   1.130 +					case SDLK_RIGHTBRACKET: ch = '}'; break;
   1.131 +					case SDLK_BACKQUOTE:    ch = ''; break;
   1.132 +
   1.133 +					default:
   1.134 +						ch = 0; /* Map to zero character if we don't understand it */
   1.135 +						break;
   1.136 +					}
   1.137 +				}
   1.138 +
   1.139 +			} else if (ch > 126)
   1.140 +			{
   1.141 +				/* SDL key code < 126 map directly onto their Unicode equivalents */
   1.142 +				/* Keypad 0 to 9 maps to numeric equivalent */
   1.143 +				if (ch >= SDLK_KP0 && ch <= SDLK_KP9) ch = ch - SDLK_KP0 + '0';
   1.144 +				else
   1.145 +				{
   1.146 +					/* Following switch maps other keys that produce an Ascii value */
   1.147 +					switch(ch)
   1.148 +					{
   1.149 +					case SDLK_KP_PERIOD:   ch = '.'; break;
   1.150 +					case SDLK_KP_DIVIDE:   ch = '/'; break;
   1.151 +					case SDLK_KP_MULTIPLY: ch = '*'; break;
   1.152 +					case SDLK_KP_MINUS:    ch = '-'; break;
   1.153 +					case SDLK_KP_PLUS:     ch = '+'; break;
   1.154 +					case SDLK_KP_EQUALS:   ch = '='; break;
   1.155 +
   1.156 +					default:
   1.157 +						/* If we don't know what it is set the Unicode to 0 */
   1.158 +						ch = 0;
   1.159 +						break;
   1.160 +					}
   1.161 +				}
   1.162 +			}			
   1.163  		}
   1.164  				
   1.165  		keysym->unicode = ch;
   1.166 @@ -455,4 +538,3 @@
   1.167  }
   1.168  
   1.169  /* end of SDL_riscosevents.c ... */
   1.170 -