Ejemplo n.º 1
0
void WorldEdit::Update()
{
	if (keyboardPress(sf::Keyboard::Escape))
		GC->GSNext = Paul::MM;

	UpdateFlash();

	sf::FloatRect BoundingBox;
	
	for (int i = 0; i < Squares.size(); i++)
	{
		for (int j = 0; j < Squares[i].size(); j++)
		{
			if (Squares[i][j].getGlobalBounds().contains(GC->currentMousePosition.x, GC->currentMousePosition.y))
			{
				if (mousePress(LeftMouseButton))
					SquareColor[i][j] = sf::Color::Red;

				Squares[i][j].setFillColor(sf::Color(SquareColor[i][j].r, SquareColor[i][j].g, SquareColor[i][j].b, FlashAlphaColor));
			}
			else
				Squares[i][j].setFillColor(SquareColor[i][j]);
		}
	}
}
Ejemplo n.º 2
0
void MainMenu::Update()
{
	if (GC->currentMousePosition != GC->previousMousePosition)
	{
		for (int i = 0; i < BoundingBoxes.size(); i++)
			if (BoundingBoxes[i].contains(GC->currentMousePosition.x, GC->currentMousePosition.y))
				Selected = i;
	}

	if (keyboardPress(sf::Keyboard::Escape))
		GC->window.close();
	if (keyboardPress(sf::Keyboard::Up))
		Selected = (Selected + Options.size() - 1) % Options.size();
	if (keyboardPress(sf::Keyboard::Down))
		Selected = (Selected + 1) % Options.size();
	if (keyboardPress(sf::Keyboard::Return) ||
		mousePress(LeftMouseButton))
		SwitchState(Selected);
}
Ejemplo n.º 3
0
/*
 * Event: Key Multi Type
 * Input: QString multi_key with "+"
 */
int Event::keyboardMType(QString multi_key)
{
    //split the multi_key with "+"
    QStringList multi_key_list;
    multi_key_list = multi_key.split('+');
    for(int i = 0; i < multi_key_list.size(); i++){
        if(!virtual_key_code[multi_key_list[i]].isValid()){
            return INPUT_ERROR;
        }
    }
    //keys in list press
    for(int i = 0; i < multi_key_list.size(); i++){
        keyboardPress(multi_key_list[i]);
    }
    //keys in list release
    for(int i = 0; i < multi_key_list.size(); i++){
        keyboardRelease(multi_key_list[i]);
    }
    return 0;
}
int keyboardWrite(uint8_t c)
{        
        uint8_t p = keyboardPress(c);                // Keydown
        /*uint8_t r =*/ keyboardRelease(c);                // Keyup
        return (p);                                        // just return the result of press() since release() almost always returns 1
}
Ejemplo n.º 5
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t guessIdx = 0;
  int running = 0;
  int delay = 0;
  RCC_ClocksTypeDef RCC_Clocks;
  
  /* Initialize LEDs and User_Button on STM32F4-Discovery --------------------*/
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI); 
  
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED5);
  STM_EVAL_LEDInit(LED6);
  
  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
  STM_EVAL_LEDOff(LED4);
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOff(LED5);
  STM_EVAL_LEDOff(LED6);
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
  keyboardInit(&USB_OTG_dev);
  Demo_USBConfig();
  char guess[7];
  strcpy(guess, "400000");
  Delay(2000);
  while (1) {
    if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET) {
      //crappy debounce routine
      TimingDelay = 10;
      while ((STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET)&&(TimingDelay != 0x00));
      //now change start or stop password attempts
      if (running == 0) {
        STM_EVAL_LEDOn(LED4);
        running = 1;
      } else {
        STM_EVAL_LEDOff(LED4);
        running = 0;
      }
    }
    //mostly non blocking delay to allow stopping with button
    if (delay > 0) {
      Delay(1000);
      delay--;
    }
    if (running != 0 && delay == 0) {
      Delay(200);
      keyboardWrite(KEY_BACKSPACE);
      keyboardWrite(KEY_BACKSPACE);
      keyboardWrite(KEY_BACKSPACE);
      keyboardWrite(KEY_BACKSPACE);
      STM_EVAL_LEDToggle(LED6);
      keyboardPutString(guess);
      keyboardWrite(KEY_RETURN);
      Delay(200);
      keyboardWrite(KEY_RETURN);
      
      nextPermutation(guess, "123", 1);
      
      if ((++guessIdx % 5) == 0) {
        //try to email every 5 guesses
        keyboardReleaseAll();
        keyboardPress(KEY_LEFT_GUI);
        keyboardPress('g');
        Delay(50);
        keyboardReleaseAll();
        keyboardPutString("*****@*****.**"); //leave the preceding 'c' that is the gmail compose shortcut
        keyboardWrite(KEY_TAB);
        keyboardPutString(guess);
        keyboardWrite(KEY_TAB);
        keyboardPutString(guess);
        keyboardWrite(KEY_TAB);
        keyboardWrite(KEY_TAB);
        keyboardWrite(KEY_RETURN);
        STM_EVAL_LEDOff(LED5);
        delay = 30;
      }
    }
  }
}
Ejemplo n.º 6
0
void CPPBot::keyboard(const int key)
{
    keyboardPress(key);
    keyboardRelease(key);
}
/**
 * Called whenever an action occurs, and processes it to
 * check if it's relevant to the surface and convert it
 * into a meaningful interaction like a "click", calling
 * the respective handlers.
 * @param action Pointer to an action.
 * @param state State that the action handlers belong to.
 */
void InteractiveSurface::handle(Action *action, State *state)
{
	if (!_visible || _hidden)
		return;

	action->setSender(this);

	if (action->getDetails()->type == SDL_MOUSEBUTTONUP || action->getDetails()->type == SDL_MOUSEBUTTONDOWN)
	{
		action->setMouseAction(action->getDetails()->button.x, action->getDetails()->button.y, getX(), getY());
	}
	else if (action->getDetails()->type == SDL_MOUSEMOTION)
	{
		action->setMouseAction(action->getDetails()->motion.x, action->getDetails()->motion.y, getX(), getY());
	}

	if (action->isMouseAction())
	{
		if ((action->getAbsoluteXMouse() >= getX() && action->getAbsoluteXMouse() < getX() + getWidth()) &&
			(action->getAbsoluteYMouse() >= getY() && action->getAbsoluteYMouse() < getY() + getHeight()))
		{
			if (!_isHovered)
			{
				_isHovered = true;
				mouseIn(action, state);
			}
			mouseOver(action, state);
		}
		else
		{
			if (_isHovered)
			{
				_isHovered = false;
				mouseOut(action, state);
			}
		}
	}

	if (action->getDetails()->type == SDL_MOUSEBUTTONDOWN)
	{
		if (_isHovered && !_buttonsPressed[action->getDetails()->button.button])
		{
			_buttonsPressed[action->getDetails()->button.button] = true;
			mousePress(action, state);
		}
	}
	else if (action->getDetails()->type == SDL_MOUSEBUTTONUP)
	{
		if (_buttonsPressed[action->getDetails()->button.button])
		{
			_buttonsPressed[action->getDetails()->button.button] = false;
			mouseRelease(action, state);
			if (_isHovered)
			{
				mouseClick(action, state);
			}
		}
	}

	if (_isFocused)
	{
		if (action->getDetails()->type == SDL_KEYDOWN)
		{
			keyboardPress(action, state);
		}
		else if (action->getDetails()->type == SDL_KEYUP)
		{
			keyboardRelease(action, state);
		}
	}
}
Ejemplo n.º 8
0
/**
 * Called whenever an action occurs, and processes it to
 * check if it's relevant to the surface and convert it
 * into a meaningful interaction like a "click", calling
 * the respective handlers.
 * @param action Pointer to an action.
 * @param state State that the action handlers belong to.
 */
void InteractiveSurface::handle(Action *action, State *state)
{
	if (!_visible || _hidden)
		return;

	action->setSender(this);

	if (action->getDetails()->type == SDL_MOUSEBUTTONUP || action->getDetails()->type == SDL_MOUSEBUTTONDOWN)
	{
		action->setMouseAction(action->getDetails()->button.x, action->getDetails()->button.y, getX(), getY());
	}
	else if (action->getDetails()->type == SDL_MOUSEMOTION)
	{
		action->setMouseAction(action->getDetails()->motion.x, action->getDetails()->motion.y, getX(), getY());
	}

	if (action->isMouseAction())
	{
		if ((action->getAbsoluteXMouse() >= getX() && action->getAbsoluteXMouse() < getX() + getWidth()) &&
			(action->getAbsoluteYMouse() >= getY() && action->getAbsoluteYMouse() < getY() + getHeight()))
		{
			if (!_isHovered)
			{
				_isHovered = true;
				mouseIn(action, state);
			}
			if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION)
			{
				_buttonsPressed = SDL_GetMouseState(0, 0);
				for (Uint8 i = 1; i <= NUM_BUTTONS; ++i)
				{
					if (isButtonPressed(i))
					{
						action->getDetails()->button.button = i;
						mousePress(action, state);
					}
				}
			}
			mouseOver(action, state);
		}
		else
		{
			if (_isHovered)
			{
				_isHovered = false;
				mouseOut(action, state);
				if (_listButton && action->getDetails()->type == SDL_MOUSEMOTION)
				{
					for (Uint8 i = 1; i <= NUM_BUTTONS; ++i)
					{
						if (isButtonPressed(i))
						{
							setButtonPressed(i, false);
						}
						action->getDetails()->button.button = i;
						mouseRelease(action, state);
					}
				}
			}
		}
	}

	if (action->getDetails()->type == SDL_MOUSEBUTTONDOWN)
	{
		if (_isHovered && !isButtonPressed(action->getDetails()->button.button))
		{
			setButtonPressed(action->getDetails()->button.button, true);
			mousePress(action, state);
		}
	}
	else if (action->getDetails()->type == SDL_MOUSEBUTTONUP)
	{
		if (isButtonPressed(action->getDetails()->button.button))
		{
			setButtonPressed(action->getDetails()->button.button, false);
			mouseRelease(action, state);
			if (_isHovered)
			{
				mouseClick(action, state);
			}
		}
	}

	if (_isFocused)
	{
		if (action->getDetails()->type == SDL_KEYDOWN)
		{
			keyboardPress(action, state);
		}
		else if (action->getDetails()->type == SDL_KEYUP)
		{
			keyboardRelease(action, state);
		}
	}
}