int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId)
{
	int i;
	SDL_keysym keysym;
	int processed = 0;

	
	if( !touchscreenKeyboardShown )
		return 0;

	
	if( action == MOUSE_DOWN )
	{
		//__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action);
		if( InsideRect( &arrows, x, y ) )
		{
			processed = 1;
			if( pointerInButtonRect[MAX_BUTTONS] == -1 )
			{
				pointerInButtonRect[MAX_BUTTONS] = pointerId;
				if( SDL_ANDROID_isJoystickUsed )
				{
					if( SDL_ANDROID_CurrentJoysticks[0] != NULL )
					{
						SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, -(x - arrows.x - arrows.w / 2) * 65534 / arrows.w );
						SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, -(y - arrows.y - arrows.h / 2) * 65534 / arrows.h );
					}
				}
				else
				{
					i = ArrowKeysPressed(x, y);
					if( i & ARROW_UP )
						SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) );
					if( i & ARROW_DOWN )
						SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) );
					if( i & ARROW_LEFT )
						SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) );
					if( i & ARROW_RIGHT )
						SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
					oldArrows = i;
				}
			}
		}

		for( i = 0; i < MAX_BUTTONS; i++ )
		{
			if( ! buttons[i].h || ! buttons[i].w )
				continue;
			if( InsideRect( &buttons[i], x, y) )
			{
				processed = 1;
				if( pointerInButtonRect[i] == -1 )
				{
					pointerInButtonRect[i] = pointerId;
					if( i == BUTTON_TEXT_INPUT )
						SDL_ANDROID_ToggleScreenKeyboardTextInput();
					else
						SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym(buttonKeysyms[i], &keysym) );
					if( i < AutoFireButtonsNum )
					{
						ButtonAutoFire[i] = 0;
						if(touchscreenKeyboardTheme == 0)
						{
							ButtonAutoFireX[i] = x;
							ButtonAutoFireRot[i] = 0;
						}
						else
						{
							ButtonAutoFireX[i*2] = 0;
							ButtonAutoFireX[i*2+1] = 0;
							ButtonAutoFireRot[i] = x;
							ButtonAutoFireDecay[i] = SDL_GetTicks();
						}
					}
				}
			}
		}
	}
	else
	if( action == MOUSE_UP )
	{
		//__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action);
		if( pointerInButtonRect[MAX_BUTTONS] == pointerId )
		{
			processed = 1;
			pointerInButtonRect[MAX_BUTTONS] = -1;
			if( SDL_ANDROID_isJoystickUsed )
			{
				if( SDL_ANDROID_CurrentJoysticks[0] )
				{
					SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, 0 );
					SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, 0 );
				}
			}
			else
			{
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) );
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) );
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) );
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
				oldArrows = 0;
			}
		}
		for( i = 0; i < MAX_BUTTONS; i++ )
		{
			if( ! buttons[i].h || ! buttons[i].w )
				continue;
			if( pointerInButtonRect[i] == pointerId )
			{
				processed = 1;
				pointerInButtonRect[i] = -1;
				if( i < AutoFireButtonsNum && ButtonAutoFire[i] )
				{
					ButtonAutoFire[i] = 2;
				}
				else
				{
					if( i != BUTTON_TEXT_INPUT )
						SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) );
				}
				if( i < AutoFireButtonsNum )
				{
					if(touchscreenKeyboardTheme == 0)
					{
						ButtonAutoFireX[i] = 0;
					}
					else
					{
						ButtonAutoFireX[i*2] = 0;
						ButtonAutoFireX[i*2+1] = 0;
					}
				}
			}
		}
	}
	else
	if( action == MOUSE_MOVE )
	{
		// Process cases when pointer enters button area (it won't send keypress twice if button already pressed)
		processed = SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId);
		
		// Process cases when pointer leaves button area
		// TODO: huge code size, split it or somehow make it more readable
		if( pointerInButtonRect[MAX_BUTTONS] == pointerId )
		{
			processed = 1;
			if( ! InsideRect( &arrows, x, y ) )
			{
				pointerInButtonRect[MAX_BUTTONS] = -1;
				if( SDL_ANDROID_isJoystickUsed )
				{
					if( SDL_ANDROID_CurrentJoysticks[0] )
					{
						SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, 0 );
						SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, 0 );
					}
				}
				else
				{
					SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) );
					SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) );
					SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) );
					SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
					oldArrows = 0;
				}
			}
			else
			{
				if( SDL_ANDROID_isJoystickUsed )
				{
					if( SDL_ANDROID_CurrentJoysticks[0] )
					{
						SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 0, -(x - arrows.x - arrows.w / 2) * 65534 / arrows.w );
						SDL_PrivateJoystickAxis(SDL_ANDROID_CurrentJoysticks[0], 1, -(y - arrows.y - arrows.h / 2) * 65534 / arrows.h );
					}
				}
				else
				{
					i = ArrowKeysPressed(x, y);
					if( i != oldArrows )
					{
						if( oldArrows & ARROW_UP && ! (i & ARROW_UP) )
							SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) );
						if( oldArrows & ARROW_DOWN && ! (i & ARROW_DOWN) )
							SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) );
						if( oldArrows & ARROW_LEFT && ! (i & ARROW_LEFT) )
							SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) );
						if( oldArrows & ARROW_RIGHT && ! (i & ARROW_RIGHT) )
							SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
						if( i & ARROW_UP )
							SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) );
						if( i & ARROW_DOWN )
							SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) );
						if( i & ARROW_LEFT )
							SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) );
						if( i & ARROW_RIGHT )
							SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
					}
					oldArrows = i;
				}
			}
		}
		for( i = 0; i < AutoFireButtonsNum; i++ )
		{
			if( pointerInButtonRect[i] == pointerId )
			{
				processed = 1;
				if( ! InsideRect( &buttonsAutoFireRect[i], x, y ) )
				{
					pointerInButtonRect[i] = -1;
					if( !ButtonAutoFire[i] )
					{
						if( i != BUTTON_TEXT_INPUT )
							SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) );
					}
					else
					{
						ButtonAutoFire[i] = 2;
					}
					if(touchscreenKeyboardTheme == 0)
					{
						ButtonAutoFireX[i] = 0;
					}
					else
					{
						ButtonAutoFireX[i*2] = 0;
						ButtonAutoFireX[i*2+1] = 0;
					}
				}
				else
				{
					if(touchscreenKeyboardTheme == 0)
					{
						ButtonAutoFire[i] = abs(ButtonAutoFireX[i] - x) > buttons[i].w / 2;
						if( !ButtonAutoFire[i] )
							ButtonAutoFireRot[i] = ButtonAutoFireX[i] - x;
					}
					else
					{
						int coeff = (buttonAutoFireImages[i*2+1].w > buttons[i].w) ? buttonAutoFireImages[i*2+1].w / buttons[i].w + 1 : 1;
						if( ButtonAutoFireRot[i] < x )
							ButtonAutoFireX[i*2+1] += (x - ButtonAutoFireRot[i]) * coeff;
						if( ButtonAutoFireRot[i] > x )
							ButtonAutoFireX[i*2] += (ButtonAutoFireRot[i] - x) * coeff;

						ButtonAutoFireRot[i] = x;

						if( ButtonAutoFireX[i*2] < 0 )
							ButtonAutoFireX[i*2] = 0;
						if( ButtonAutoFireX[i*2+1] < 0 )
							ButtonAutoFireX[i*2+1] = 0;
						if( ButtonAutoFireX[i*2] > buttonAutoFireImages[i*2+1].w / 2 )
							ButtonAutoFireX[i*2] = buttonAutoFireImages[i*2+1].w / 2;
						if( ButtonAutoFireX[i*2+1] > buttonAutoFireImages[i*2+1].w / 2 )
							ButtonAutoFireX[i*2+1] = buttonAutoFireImages[i*2+1].w / 2;

						if( ButtonAutoFireX[i*2] == buttonAutoFireImages[i*2+1].w / 2 &&
							ButtonAutoFireX[i*2+1] == buttonAutoFireImages[i*2+1].w / 2 )
						{
							if( ! ButtonAutoFire[i] )
								ButtonAutoFireDecay[i] = SDL_GetTicks();
							ButtonAutoFire[i] = 1;
						}
					}
				}
			}
		}
		for( i = AutoFireButtonsNum; i < MAX_BUTTONS; i++ )
		{
			if( ! buttons[i].h || ! buttons[i].w )
				continue;
			if( pointerInButtonRect[i] == pointerId )
			{
				processed = 1;
				if( ! InsideRect( &buttons[i], x, y ) )
				{
					pointerInButtonRect[i] = -1;
					if( i != BUTTON_TEXT_INPUT )
						SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) );
				}
			}
		}
	}
	
	return processed;
};
int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId)
{
	int i;
	SDL_keysym keysym;

	
	if( !touchscreenKeyboardShown )
		return 0;

	if( action == MOUSE_DOWN )
	{
		if( InsideRect( &arrows, x, y ) )
		{
			OldCoords[pointerId] = &arrows;
			i = ArrowKeysPressed(x, y);
			if( i & ARROW_UP )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) );
			if( i & ARROW_DOWN )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) );
			if( i & ARROW_LEFT )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) );
			if( i & ARROW_RIGHT )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
			oldArrows = i;
			return 1;
		}

		for( i = 0; i < nbuttons; i++ )
		{
			if( InsideRect( &buttons[i], x, y) )
			{
				OldCoords[pointerId] = &buttons[i];
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym(buttonKeysyms[i], &keysym) );
				if( i < AutoFireButtonsNum )
				{
					ButtonAutoFire[i] = 0;
					if(touchscreenKeyboardTheme == 0)
					{
						ButtonAutoFireX[i] = x;
						ButtonAutoFireRot[i] = 0;
					}
					else
					{
						ButtonAutoFireX[i*2] = 0;
						ButtonAutoFireX[i*2+1] = 0;
						ButtonAutoFireRot[i] = x;
						ButtonAutoFireDecay[i] = SDL_GetTicks();
					}
				}
				return 1;
			}
		}
	}
	else
	if( action == MOUSE_UP )
	{
		if( OldCoords[pointerId] == &arrows )
		{
			OldCoords[pointerId] = NULL;
			SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) );
			SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) );
			SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) );
			SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
			oldArrows = 0;
			return 1;
		}
		for( i = 0; i < nbuttons; i++ )
		{
			if( OldCoords[pointerId] == &buttons[i] )
			{
				if( ! ( i < AutoFireButtonsNum && ButtonAutoFire[i] ) )
				{
					SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym(buttonKeysyms[i] ,&keysym) );
				}
				else
				{
					ButtonAutoFire[i] = 2;
				}
				OldCoords[pointerId] = NULL;
				if(touchscreenKeyboardTheme == 0)
				{
					ButtonAutoFireX[i] = 0;
				}
				else
				{
					ButtonAutoFireX[i*2] = 0;
					ButtonAutoFireX[i*2+1] = 0;
				}
				return 1;
			}
		}
	}
	else
	if( action == MOUSE_MOVE )
	{
		if( OldCoords[pointerId] && !InsideRect(OldCoords[pointerId], x, y) )
		{
			SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_UP, pointerId);
			return SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId);
		}
		else
		if( OldCoords[pointerId] == &arrows )
		{
			i = ArrowKeysPressed(x, y);
			if( i == oldArrows )
				return 1;
			if( oldArrows & ARROW_UP && ! (i & ARROW_UP) )
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(UP), &keysym) );
			if( oldArrows & ARROW_DOWN && ! (i & ARROW_DOWN) )
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(DOWN), &keysym) );
			if( oldArrows & ARROW_LEFT && ! (i & ARROW_LEFT) )
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(LEFT), &keysym) );
			if( oldArrows & ARROW_RIGHT && ! (i & ARROW_RIGHT) )
				SDL_SendKeyboardKey( SDL_RELEASED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
			if( i & ARROW_UP )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(UP), &keysym) );
			if( i & ARROW_DOWN )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(DOWN), &keysym) );
			if( i & ARROW_LEFT )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(LEFT), &keysym) );
			if( i & ARROW_RIGHT )
				SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(RIGHT), &keysym) );
			oldArrows = i;
		}
		else
		{
			for(i = 0; i < AutoFireButtonsNum; i++)
			if( OldCoords[pointerId] == &buttons[i] )
			{
				if(touchscreenKeyboardTheme == 0)
				{
					ButtonAutoFire[i] = abs(ButtonAutoFireX[i] - x) > buttons[i].w / 2;
					if( !ButtonAutoFire[i] )
						ButtonAutoFireRot[i] = ButtonAutoFireX[i] - x;
				}
				else
				{
					int coeff = (buttonAutoFireImages[i*2+1].w > buttons[i].w) ? buttonAutoFireImages[i*2+1].w / buttons[i].w + 1 : 1;
					if( ButtonAutoFireRot[i] < x )
						ButtonAutoFireX[i*2+1] += (x - ButtonAutoFireRot[i]) * coeff;
					if( ButtonAutoFireRot[i] > x )
						ButtonAutoFireX[i*2] += (ButtonAutoFireRot[i] - x) * coeff;

					ButtonAutoFireRot[i] = x;

					if( ButtonAutoFireX[i*2] < 0 )
						ButtonAutoFireX[i*2] = 0;
					if( ButtonAutoFireX[i*2+1] < 0 )
						ButtonAutoFireX[i*2+1] = 0;
					if( ButtonAutoFireX[i*2] > buttonAutoFireImages[i*2+1].w / 2 )
						ButtonAutoFireX[i*2] = buttonAutoFireImages[i*2+1].w / 2;
					if( ButtonAutoFireX[i*2+1] > buttonAutoFireImages[i*2+1].w / 2 )
						ButtonAutoFireX[i*2+1] = buttonAutoFireImages[i*2+1].w / 2;

					if( ButtonAutoFireX[i*2] == buttonAutoFireImages[i*2+1].w / 2 &&
						ButtonAutoFireX[i*2+1] == buttonAutoFireImages[i*2+1].w / 2 )
					{
						if( ! ButtonAutoFire[i] )
							ButtonAutoFireDecay[i] = SDL_GetTicks();
						ButtonAutoFire[i] = 1;
					}
				}
			}
		}

		if( OldCoords[pointerId] )
			return 1;

		return SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId);
	}
	return 0;
};
int processTouchscreenKeyboard(int x, int y, int action, int pointerId)
{
		int i;
		int keysym;
		
		extern	clientStatic_t		cls;
		if(!g_use_touchscreen_icon){
			return 0;
		}
		if(cls.state != CA_ACTIVE) {
			return 0;
		
		}
		//LOGI("touch x:%d, y:%d, a:%d, id:%d", x, y, action, pointerId);
		if( action == MOUSE_DOWN )
		{
		
			if( OldCoords[pointerId] )
			{
				processTouchscreenKeyboard(x, y, MOUSE_UP, pointerId);
			}
			//do the move stuff
			if( InsideRect( &arrow, x, y ) )
			{
				 OldCoords[pointerId] = &arrow;
				 //i = ArrowKeysPressed(x, y);
				 i = ArrowKeysPressed(x, y);
				 //reset_arrow_key();
				 if( i & ARROW_UP ) {
				   Key_Event(arrowkeys[UP],SDL_PRESSED);
				 }
				 if( i & ARROW_DOWN ) {
					 Key_Event(arrowkeys[DOWN],SDL_PRESSED);
				 }
				 if( i & ARROW_LEFT ) {
					 Key_Event_Alt(arrowkeys[LEFT],SDL_PRESSED);
				 }
				 if( i & ARROW_RIGHT ) {
					 Key_Event_Alt(arrowkeys[RIGHT],SDL_PRESSED);
				 }
				 oldArrows = i;
				//__android_log_print(ANDROID_LOG_INFO, "doom", "down arrow %d",pointerId);
				return 1;
			} 
			if(show_gun) {
			  int num = SDL_ANDROID_get_number(x, y);
			  
			  if (num > 0) {
				//change the gun
				pressed_num = num;
				OldCoords[pointerId] = (SDL_Rect * )&pressed_num;
				//__android_log_print(ANDROID_LOG_INFO, "libSDL", "pressed num:%d", pressed_num);
				
				keysym = '0';
				keysym += num;
				Key_Event(keysym ,SDL_PRESSED);
				return 1;
			  }
			}

			//process other touch icon:fire ,jump ,switch gun
			for( i = 0; i < nbuttons; i++)
			{
				if( InsideRect( &buttons[i], x, y) )
				{
					OldCoords[pointerId] = &buttons[i];
					button_pressed[i] = 1;
					//LOGI("button %d is settttttttttt", i);
					if (i == SWITCH_GUN) {
					  //switch gun
					  show_gun = show_gun==0 ? 1 : 0;
					  return 1;
					}
					
					if( i == TURN) {
						//jump_press= 1;
						//Key_Event(SDL_PRESSED, buttonKeysyms[][]);
						if(x < buttons[i].x+buttons[i].w/2) {
							//SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(A), &keysym) );
							Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_PRESSED);
							oldTurn = 1;
						}
						else { 
							//SDL_SendKeyboardKey( SDL_PRESSED, GetKeysym( SDL_KEY(D), &keysym) );
							Key_Event( turnKeysyms[DpadAsturn][RIGHT],SDL_PRESSED);
							oldTurn = 2;
						}
						return 1;
					} 
					
					Key_Event(buttonKeysyms[i], SDL_PRESSED);
					
					return 1;
				}
			}
		}
		else if( action == MOUSE_UP )
		{
			if( OldCoords[pointerId] == &arrow)
			{
				OldCoords[pointerId] = NULL;
				//we draw use arrow_move, when touch up.return to the center
				//arrow_move = arrow_cricle;
				
				i = oldArrows;
				//reset_arrow_key();
				if( i & ARROW_UP ) {
				  Key_Event(arrowkeys[UP],SDL_RELEASED);
				}
				if( i & ARROW_DOWN ) {
					Key_Event(arrowkeys[DOWN],SDL_RELEASED);
				}
				if( i & ARROW_LEFT ) {
					Key_Event_Alt(arrowkeys[LEFT],SDL_RELEASED);
				}
				if( i & ARROW_RIGHT ) {
					Key_Event_Alt(arrowkeys[RIGHT],SDL_RELEASED);
				}
				oldArrows = 0;
				//__android_log_print(ANDROID_LOG_INFO, "doom", "up arrow %d",pointerId);
				return 1;
			} 

			for( i = 0; i < nbuttons; i++ )
			{
				if( OldCoords[pointerId] == &buttons[i] )
				{
					button_pressed[i] = 0;
					//LOGI("button %d is clear", i);
					OldCoords[pointerId] = NULL;
					if(i == SWITCH_GUN) {
					 // OldCoords[pointerId] = NULL;
					  //show_gun = 0;
					  return 1;
					}
					if( i == TURN) {
						
						 //jump_release= 1;
						oldTurn = 0;
						Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_RELEASED);
						Key_Event( turnKeysyms[DpadAsturn][RIGHT], SDL_RELEASED);
						return 1;
					} 
					Key_Event(buttonKeysyms[i], SDL_RELEASED);
					
					
				
					return 1;
				}
			}
			//process the gun number
			if(show_gun && OldCoords[pointerId] == (SDL_Rect * )&pressed_num) {
			  if (pressed_num>0) {
				
				keysym = '0'+pressed_num;
				Key_Event( keysym, SDL_RELEASED);
				//SDL_SendKeyboardKey(SDL_RELEASED, GetKeysym( SDL_KEY(0), &keysym)+pressed_num );
				pressed_num = -1;
				OldCoords[pointerId] = NULL;
				return 1;
			  }
			}
		}
		else if( action == MOUSE_MOVE )
		{
			//finger slip to ohter place
	 		if( OldCoords[pointerId] && !InsideRect(OldCoords[pointerId], x, y) )
	 		{
	 			processTouchscreenKeyboard(x, y, MOUSE_UP, pointerId);
	 			return processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId);
	 		}
	
			 if( OldCoords[pointerId] == &arrow )
			 {
				i = ArrowKeysPressed(x, y);
				if( i == oldArrows )
					return 1;
				
		
				if( oldArrows & ARROW_UP && ! (i & ARROW_UP) )
					Key_Event(arrowkeys[UP],SDL_RELEASED);
				if( oldArrows & ARROW_DOWN && ! (i & ARROW_DOWN) )
					Key_Event(arrowkeys[DOWN],SDL_RELEASED);
				if( oldArrows & ARROW_LEFT && ! (i & ARROW_LEFT) )
					Key_Event_Alt(arrowkeys[LEFT],SDL_RELEASED);
				if( oldArrows & ARROW_RIGHT && ! (i & ARROW_RIGHT) )
					Key_Event_Alt(arrowkeys[RIGHT],SDL_RELEASED);
				if( i & ARROW_UP )
					Key_Event(arrowkeys[UP],SDL_PRESSED);
				if( i & ARROW_DOWN )
					Key_Event(arrowkeys[DOWN],SDL_PRESSED);
				if( i & ARROW_LEFT )
					Key_Event_Alt(arrowkeys[LEFT],SDL_PRESSED);
				if( i & ARROW_RIGHT )
					Key_Event_Alt(arrowkeys[RIGHT],SDL_PRESSED);
				oldArrows = i;
			} else if(OldCoords[pointerId] == &buttons[TURN]){
				 i = TurnKeyPressed(x, y);
				 
				 if( i == oldTurn)
					 return 1;
				 if(oldTurn == 1 && i == 2) {
					 Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_RELEASED);
					 Key_Event( turnKeysyms[DpadAsturn][RIGHT], SDL_PRESSED);
				 } else if(oldTurn == 2 && i == 1) {
				 
				 	 Key_Event( turnKeysyms[DpadAsturn][RIGHT], SDL_RELEASED);
					 Key_Event( turnKeysyms[DpadAsturn][LEFT], SDL_PRESSED);
				 
				 }
				 oldTurn =	i;
			}
	
			if( OldCoords[pointerId] )
				return 1;
		
			//return processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId);
		}
		return 0;
}