Esempio n. 1
0
/**
 * Hides the current window. 
 * An input of screen height is taken and divided by a constant value to determine how many times to press the down arrow.
 **/
void HideCurWindow(int screenHeight) {
    Alt(KEY_SPACE);
    PressKey(KEY_M, 1);
    PressKey(KEY_DOWN, ((int)(screenHeight/7.2)));
    Mouse.click();
    delay(delayAm);
}
Esempio n. 2
0
void Test(int row, int col, int bomb, int &y, int &x)
{
	struct pole** src;
	src = CreateArray(row, col);
	if (src == NULL)
		cout << "Problem\n";
	Random(src, row, col, bomb);
		//	bool wygrana = IsWin(src, row, col, bomb);
	bool bomba = false;
	int zakryte = row*col; // zakryte pola
	while (zakryte != bomb) {
		Write(src, row, col, y, x);
		//CountFlags(src, row, col, bomb);
		//ShowCell(src, row, col, y, x);
		PressKey(src, row, col, bomb, y, x,zakryte);
		bomba = IfBomb(src, row, col, y, x);
		if (bomba == true) break;
		system("cls");
    }
	x = 0;
	y = 0;
	if (zakryte == bomb) { //warunek wygranej
		cout << "Gratulacje, wygrales!\n\n";
	}
	Write(src, row, col, y, x);
	cout << "\n";
	DeleteArray(&src, row);
}
Esempio n. 3
0
void OCPiano::mousePressEvent(QMouseEvent *event)
{
    //QPointF m(mapToScene(event->pos()));
    int Pitch=PosToPitch(event->pos());
    if ((Pitch > 0) & (Pitch < 128))
    {
        PressKey(Pitch,event->modifiers()&Qt::ShiftModifier,event->button()&Qt::RightButton);
        Paint();
    }
}
Esempio n. 4
0
void Keyboard::PressUnpressKey(AEKeys key, bool isDown)
{
	if(isDown)
	{
		PressKey(key);
	}
	else
	{
		UnpressKey(key);
	}
}
Esempio n. 5
0
void ReadKeyboard ()
{
    // Make a copy of the master key table with the real keyboard states
    memcpy(afKeyStates, afKeys, sizeof(afKeyStates));

    // Left-Alt can optionally be used as the SAM Cntrl key
    if (GetOption(altforcntrl) && IsPressed(VK_LMENU))
    {
        ReleaseKey(VK_LMENU);
        PressKey(VK_RCONTROL);
    }

    // AltGr can optionally be used for SAM Edit
    if (GetOption(altgrforedit) && IsPressed(VK_RMENU))
    {
        // Release AltGr and press the context menu key (also used for SAM Edit)
        ReleaseKey(VK_RMENU);
        PressKey(VK_APPS);

        // Also release Ctrl and Alt, which is how AltGr often behaves
        ReleaseKey(VK_LCONTROL);
        ReleaseKey(VK_LMENU);
    }
}
Esempio n. 6
0
void Keyb_SendKeys(String text, long finalDelay, long delayBetweenKeys)
{
    Array <wchar> virt;
    bool inKey = false;
    String key = "";
    WString wtext(text);
    for (int i = 0; i < wtext.GetCount(); ++i) {
        bool vk = false;
        Sleep(delayBetweenKeys);
        wchar c = wtext[i];
        if (c == '{')
            inKey = true;
        else if (c == '}') {
            if (key == "{")
                c = '{';
            else {
                c = GetKeyCode(key);
                vk = true;
            }
            inKey = false;
            key = "";
        } else if (inKey == 1)
            key.Cat(c);
        else if (c == '\n') {
            c = GetKeyCode("RETURN");
            vk = true;
        }
        if (inKey == false) {
            if (!vk)
                PressKey(c);
#if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64)
            else {
                PressKeyVK(c, true);
                virt.Add(c);
            }
#endif
        }
    }
#if defined(PLATFORM_WIN32) || defined (PLATFORM_WIN64)
    for (int i = 0; i < virt.GetCount(); ++i)
        PressKeyVK(virt[i], false, true);
#endif
    Sleep(finalDelay);
}
Esempio n. 7
0
File: Tetris.c Progetto: Jn58/Tetris
void main(){
	//sndPlaySound("C/song.wav",SND_ASYNC | SND_LOOP);
	NoCursor();
	system("mode con cols=35 lines=25");
	srand((unsigned)time(NULL));
	system("cls");
	DrawScreen();
	Next.type = rand() % 7;
	Next.pos.x = WIDTH+4;
	Next.pos.y = 8;
	Next.rotation=0;
	Brick.t=BRICK;
	expect.pos.x=5;
	expect.pos.y=10;

	while(1){
		DisplayNext(FALSE);
		Brick.type = Next.type;
		Next.type = rand() % 7;
		DisplayNext(TRUE);
		Brick.pos.x = 5;
		Brick.pos.y = 3;
		Brick.rotation = 0;
		expect=Brick;
		Expect();
		DisplayBrick(Brick,TRUE);
			

		if(CanMove(Brick) != TRUE) break; 
		Delay = 0;
		if(!(rand()%15>0))
			item=1;
		while(1){
			brink^=1;
			Delay++;
			if(Delay == 20 )
			{
				if(MoveDown()){
					break;
				}
				Delay = 0;
			}
			if(PressKey()) break;
			DisplayBrick(Brick,TRUE);	
			Sleep(speed);
		}
		FixBrick();
		PrintScore();
		if(speed>30)
 			speed=50-(score/100)*2;
		else if(speed>15)
			speed=30-((score-1000)/200);
		else if(speed>10)
			speed=15-(score-4000)/600;
		else if(speed>1)
			speed=10-(score-7000)/1000;
		else
			speed=1;


		if(score>=stage*2000){
			stage++;
			DrawScreen();
			gotoxy(9,12);
			printf("Stage %d",stage);
			Sleep(1000);
			while(_kbhit())
				_getch();
			_getch();
			DrawScreen();
		}
		item=0;
		
	}

	system("cls");
	gotoxy(12,12); 
	puts("GAME OVER");
	_getch();
}
Esempio n. 8
0
//-----------------------------------------------------------
//friend of TPK on key handler
//extract key string and pass to handler
//process keypushes etc on return
void OnKeyHandler(bool IsFnKey,CString Key)
{
	CString k=Key;
	CString uk=k.UpperCase();

	int count;
	bool CallKeyHandler=false;

	//delay
	bool IsSleep=uk.Pos("SLEEP")==1;

	//*********************
	//clear clipboard
	bool IsClearClip=uk.Pos("EMPTYCLIP")==1;

	//run
	bool IsRun=uk.Pos("RUN ")==1;

	//{\0xxx}
	bool IsDirect=k.Pos("\\")==1 && k.GetLength()>1;

	if (k=="\\")
	{
		IsDirect=false;
		IsFnKey=false;
	}

	//function key? or clear clipboard or run
	if(IsFnKey || IsSleep || IsDirect  || IsClearClip || IsRun)
	{
		//get count value & strip out count characters
		if (!IsRun)
		{
			count=GetFunctionKeyCount(k);
		}

		if(IsAFunctionKey(uk) || IsDirect)
		{
			//not a control key?
			if (GetControlKey(uk)==(byte)-1)
				k="{"+uk+"}";

			CallKeyHandler=true;

		}

		//sleep or clear clipboard or run
		if (IsSleep || IsClearClip || IsRun)
		{
			k="{"+Key.UpperCase()+"}";
			CallKeyHandler=true;
		}
	}
	else
	{
		if (k.GetLength()==1)
		{
			CallKeyHandler=true;

		}
	}

	if (!CallKeyHandler)
		return;


	//set up shiftstate to pass here
	//**************************
	TShiftState KeyState,CopyOfKeyState;
	if (ShiftOn)
		KeyState<<ssShift;

	if (ControlOn)
		KeyState<<ssCtrl;

	if (AltOn)
		KeyState<<ssAlt;

	//keep a copy
	CopyOfKeyState=KeyState;

	//pass to onkey & delay handler
	//************************
	GTPK->HandleOnKeyEvent(k,KeyState);

	//returned keys
	//************************
	CString returned=k;
	int rl=returned.GetLength();
	uk=returned.UpperCase();

	if (rl==0)
		return;

	//process returned shiftstate
	//**************
	//changed?
	if (KeyState!=CopyOfKeyState)
	{
		//set key states
		SetKeyStates(KeyState);
	}

	//process keys returned
	//***************************
	IsSleep=uk.Pos("{SLEEP")==1;

	//clear clipboard
	IsClearClip=uk.Pos("{EMPTYCLIP")==1;

	//run
	IsRun=uk.Pos("{RUN ")==1;

	//single key(s)?
	if (rl<3)
	{
		PushAString(returned);
	}
	else
	{
		if (returned[1]=='{' && returned[rl]=='}')
		{
			//strip out braces
			CString fk=returned.SubString(2,rl-2).UpperCase();

			bool IsNL=k=="{NEWLINE}" || uk=="{NL}";

			//is it a function key?
			if(IsAFunctionKey(fk) && !IsNL)
			{
				PushFnKey(fk);
			}
			//CRLF
			else if (IsNL)
			{
				// New line = Carriage return & Line Feed = ^M^J
				for (int i=0;i<count;i++)
				{
					if (DOSKey)//ANSI equivalent
					{
						PushCTRLKey('M');
						PushCTRLKey('J');
					}
					else
					{
						UINT ScanKey = MapVirtualKey(VK_RETURN, 0);
						PressKey(VK_RETURN,ScanKey);
						ScanKey = MapVirtualKey(VK_LINEFEED, 0);
						PressKey(VK_LINEFEED,ScanKey);
					}
				}
			}
			//direct {\xxxx}
			else if(fk.Pos("\\")==1 && fk.GetLength()>1)
			{
				if (fk.GetLength()>1)
				{
					//start key presses
					ALTOn();

					//step along numbers
					for (int numpointer=2;numpointer<=fk.GetLength();numpointer++)
					{
						char number=fk[numpointer];

						if (number>='0' && number<='9')
						{
							//get numpad key
							byte npk[]={VK_NUMPAD0,VK_NUMPAD1,VK_NUMPAD2,VK_NUMPAD3,VK_NUMPAD4
								,VK_NUMPAD5,VK_NUMPAD6,VK_NUMPAD7,VK_NUMPAD8,VK_NUMPAD9};

							byte numpadkey=npk[number-'0'];

							//press key
							PressKey(numpadkey,MapVirtualKey(numpadkey,0));
						}

					}

					//all done
					ALTOff();
				}
			}
			//delay
			else if(IsSleep)//sleep
			{
				int count=GetFunctionKeyCount(fk);
				DoDelay(count);
			}
			//clear clipboard
			else if (IsClearClip)
			{
				int count=GetFunctionKeyCount(fk);
				for (int c=0;c<count;c++)
				{
					if (OpenClipboard(NULL))
					{
						EmptyClipboard();
						CloseClipboard();
					}
				}
			}
			else if (IsRun)//run
			{
				CString runcmd=Key.SubString(4,fk.GetLength());
				WinExec(runcmd.c_str(),SW_SHOWNORMAL);
			}

			else //do single keys
			{
				PushAString(returned);
			}
		}
		else
		{
			PushAString(returned);
		}
	}

	//reset changed shiftstate
	//**************
	//changed?
	if (KeyState!=CopyOfKeyState)
	{
		//reset key states
		SetKeyStates(CopyOfKeyState);
	}

	//do inter-key delay if not a sleep command
	if(!IsSleep)
	{
		GTPK->DoKeyDelay();
	}
}
Esempio n. 9
0
//-----------------------------------------------------------
//function keys
void PushFnKey(CString KeyCode)
{

	// Outputs function key. KeyCode may have a number of times to be output
	LONG NumPushes;
	INT index;
	CString FnKey;
	CString OrigCode;
	bool isfnkey=false;

	// Work out which function key to push and how many times

	//get key press count & strip out count characters
	NumPushes=GetFunctionKeyCount(KeyCode);

	//keep a copy
	OrigCode=KeyCode;

	FnKey=KeyCode.UpperCase();

	//direct code entry
	if (FnKey.Pos("\\")==1)
	{
		ProcessFuncKey(FnKey);
		return;
	}

	//braces
	if (FnKey=="LEFTBRACE" || FnKey=="RIGHTBRACE")
	{
		char pc=FnKey.Pos("LEFT")<1 ? '}' : '{';
		for (index=1;index<=NumPushes;index++)
		{
			PushAKey(pc);
		}
		return;
	}

	//search for F key
	byte fnkey=GetFunctionKey(FnKey);

	if (fnkey==(byte)-1)
		fnkey=GetControlKey(FnKey);

	if (fnkey!=(byte)-1)
	{
		isfnkey=true;
	}

	//press f key
	if (isfnkey)
	{
		bool dodos=false;

		//do DOS conversion?
		if (DOSKey)
		{
			byte vk[]={VK_BELL,VK_BREAK,VK_RETURN,VK_ESCAPE,VK_CLEAR,VK_LINEFEED,VK_TAB};
			char dk[]={'G','C','M','[','L','J','I'};

			//search for key equivalent
			for (int i=0;i<sizeof(vk)/sizeof(vk[0]);i++)
			{
				if (fnkey==vk[i])
				{
					//match found
					dodos=true;

					for (index=1;index<=NumPushes;index++)
					{
						//do key press
						PushCTRLKey(dk[i]);
					}
					break;
				}
			}
		}
		if (!dodos)//normal fkey
		{
			for (index=1;index<=NumPushes;index++)
			{
				//reserved characters
				if (GetControlKey(fnkey)!=(byte)-1)
				{
					PushAKey(fnkey);
				}
				else
				{
					//full printscreen
					if (fnkey==VK_SNAPSHOT && !AltOn)
					{
						PressKey(fnkey,1);
					}
					else
					{
						PressKey(fnkey,MapVirtualKey(fnkey,0));
					}
				}
			}
		}
	}
	//sleeep or NL or clear clipboard or run
	else if(FnKey!="SLEEP" && FnKey!="NEWLINE" && FnKey!="NL"  && FnKey !="EMPTYCLIP"
		&& FnKey.Pos("RUN ")!=1)
	{
		// Ordinary keys
		for (index=1; index<=NumPushes; index++)
		{
			for (int i=0;i<OrigCode.GetLength();i++)
			{
				char ss=OrigCode[i+1];

				//watch for {~ 2}
				if(ss!='~' || OrigCode=="~")
				{
					OnKeyHandler(false,ss);
				}
				else
				{
					//{hello world~ 3}
					OnKeyHandler(true,"ENTER");
				}
			}
		}
	}
}
Esempio n. 10
0
//-----------------------------------------------------------
void PushAKey(CHAR k)
{

	bool doshift=false;
	bool doalt=false;
	bool doctrl=false;

	DWORD vks=VkKeyScan(k);
	DWORD oeks=OemKeyScan(k);

	if(oeks!=(DWORD)-1) //standard key
	{
		if (oeks & 0x00020000)
		{
			doshift=true;
		}

		if (oeks & 0x00040000)
		{
			doctrl=true;
		}

		if (oeks & 0x00080000)
		{
			doalt=true;
		}
	}
	//not a standard key
	else
	{
		oeks=vks;

		if (oeks & 0x0100)
		{
			doshift=true;
		}

		if (oeks & 0x0200)
		{
			doctrl=true;
		}

		if (oeks & 0x0400)
		{
			doalt=true;
		}

	}

	//invalid key code
	if (oeks==(DWORD)-1 || vks==(DWORD)-1)
		return;

	//no need for shift if it's already on
	if (ShiftOn)
	{
		doshift=false;
	}

	//no need for ctrl if it's already on
	if (ControlOn)
	{
		doctrl=false;
	}

	//no need for alt if it's already on
	if (AltOn)
	{
		doalt=false;
	}

	//shift on
	if (doshift)
	{
		SHIFTOn();
	}

	//ctrl on
	if (doctrl)
	{
		CTRLOn();
	}

	//alt on
	if (doalt)
	{
		ALTOn();
	}

	// Press the key
	PressKey((BYTE)vks, (BYTE)oeks);

	//shift off
	if (doshift)
	{
		SHIFTOff();
	}

	//ctrl off
	if (doctrl)
	{
		CTRLOff();
	}

	//alt off
	if (doalt)
	{
		ALTOff();
	}


}
Esempio n. 11
0
void TypePassword(char *szPwd)
{
	for(int i = 0; i < strlen(szPwd); i++)
		PressKey(szPwd[i]);
}
Esempio n. 12
0
STDMETHODIMP CSoftKeyboard::PressAndReleaseKeys(
                BSTR bstrKeyStrokes)

/*++
Routine Description:
    Implement the PressAndRelease method for the interface
    ISoftKeyboard. This simulate a key stroke for a UNICODE character

Synchronization: 
    None
 
Arguments:
    bstrKeyStrokes - Keystrokes to be simulated
    
Return Value:
    E_FAIL 
        Could not generate a sequence of keycodes to simulate a keystroke.
    E_INVALIDARG
        Invalid keystroke length.
    S_OK
        Success.
--*/
{
    HRESULT hr = S_OK;
    UINT nUnits = 0;
    KBD_KEYCODE* pKeyCodes = NULL;

    UINT nSize = SysStringLen(bstrKeyStrokes);

    // Check if string is not NULL
    IfFalseHrGo(nSize != 0, E_INVALIDARG);

    // Check is Translator property is set
    IfFalseHrGo(NULL != m_piSoftKbdTranslator, E_UNEXPECTED);

    hr = m_piSoftKbdTranslator->TranslateString2Keycodes(nSize, bstrKeyStrokes, &nUnits, &pKeyCodes);
    IfFailHrGo(hr);

    // Go through returned sequence and queue it for processing
    for(UINT i = 0; i < nUnits; i++)
    {
        // Call PressKey method
        if (KEY_MAKE == pKeyCodes[i].ucFlag) {
            IfFailHrGo(PressKey(pKeyCodes[i].KeyCode));
        }
        // Call ReleaseKey method
        else if (KEY_BREAK == pKeyCodes[i].ucFlag) {
            IfFailHrGo(ReleaseKey(pKeyCodes[i].KeyCode));
        }
        // Call HitKeyOnce method
        else if ((KEY_BREAK | KEY_MAKE) == pKeyCodes[i].ucFlag) {
            IfFailHrGo(HitKeyOnce(pKeyCodes[i].KeyCode));
        }
        // Should never hit this code, but check anyway
        else {
            IfFailHrGo(E_FAIL);
        }
    }

Exit:
    m_pMalloc->Free(pKeyCodes);
    return hr;

} // CSoftKeyboard::PressAndReleaseKeys
Esempio n. 13
0
void KeyEvent(CARD32 keysym, Bool down)
{
  int i;
  unsigned state, new_state;
  KeyCode keycode;

  unsigned level_three_mask;
  KeyCode shift_press = 0, level_three_press = 0;
  KeyCode *shift_release = NULL, *level_three_release = NULL;

  /*
   * Release events must match the press event, so look up what
   * keycode we sent for the press.
   */
  if (!down) {
    for (i = 0; i < 256; i++) {
      if (pressedKeys[i] == keysym) {
        pressedKeys[i] = NoSymbol;
        PressKey(kbdDevice, i, FALSE, "keycode");
        mieqProcessInputEvents();
        return;
      }
    }

    /*
     * This can happen quite often as we ignore some
     * key presses.
     */
    if (xkbDebug)
      rfbLog("Unexpected release of keysym 0x%x\n", keysym);

    return;
  }

  /*
   * Since we are checking the current state to determine if we need
   * to fake modifiers, we must make sure that everything put on the
   * input queue is processed before we start. Otherwise, shift may be
   * stuck down.
   */
  mieqProcessInputEvents();

  state = GetKeyboardState();

  keycode = KeysymToKeycode(keysym, state, &new_state);

  /* Try some equivalent keysyms if we couldn't find a perfect match */
  if (keycode == 0) {
    for (i = 0; i < sizeof(altKeysym) / sizeof(altKeysym[0]); i++) {
      KeySym altsym;

      if (altKeysym[i].a == keysym)
        altsym = altKeysym[i].b;
      else if (altKeysym[i].b == keysym)
        altsym = altKeysym[i].a;
      else
        continue;

      keycode = KeysymToKeycode(altsym, state, &new_state);
      if (keycode != 0)
        break;
    }
  }

  /* We don't have lock synchronisation... */
  if (IsLockModifier(keycode, new_state) && ignoreLockModifiers) {
    if (xkbDebug)
      rfbLog("Ignoring lock key (e.g. caps lock)\n");
    return;
  }

  /* No matches. Will have to add a new entry... */
  if (keycode == 0) {
    keycode = AddKeysym(keysym, state);
    if (keycode == 0) {
      rfbLog("ERROR: Could not add new keysym 0x%x\n", keysym);
      return;
    }

    rfbLog("Mapped unknown keysym 0x%x to keycode %d\n", keysym, keycode);

    /*
     * The state given to addKeysym() is just a hint and
     * the actual result might still require some state
     * changes.
     */
    keycode = KeysymToKeycode(keysym, state, &new_state);
    if (keycode == 0) {
      rfbLog("ERROR: Cannot generate keycode for newly-added keysym 0x%x\n",
             keysym);
      return;
    }
  }

  /*
   * X11 generally lets shift toggle the keys on the numeric pad
   * the same way NumLock does. This is however not the case on
   * other systems like Windows. As a result, some applications
   * get confused when we do a fake shift to get the same effect
   * that having NumLock active would produce.
   *
   * Until we have proper NumLock synchronisation (so we can
   * avoid faking shift), we try to avoid the fake shifts if we
   * can use an alternative keysym.
   */
  if (((state & ShiftMask) != (new_state & ShiftMask)) &&
      avoidShiftNumLock && IsAffectedByNumLock(keycode)) {
    KeyCode keycode2 = 0;
    unsigned new_state2;

    if (xkbDebug)
      rfbLog("Finding alternative to keysym 0x%x to avoid fake shift for numpad\n",
             keysym);

    for (i = 0; i < sizeof(altKeysym) / sizeof(altKeysym[0]); i++) {
      KeySym altsym;

      if (altKeysym[i].a == keysym)
        altsym = altKeysym[i].b;
      else if (altKeysym[i].b == keysym)
        altsym = altKeysym[i].a;
      else
        continue;

      keycode2 = KeysymToKeycode(altsym, state, &new_state2);
      if (keycode2 == 0)
        continue;

      if (((state & ShiftMask) != (new_state2 & ShiftMask)) &&
          IsAffectedByNumLock(keycode2))
        continue;

      break;
    }

    if (i == sizeof(altKeysym) / sizeof(altKeysym[0])) {
      if (xkbDebug)
        rfbLog("No alternative keysym found\n");
    } else {
      keycode = keycode2;
      new_state = new_state2;
    }
  }

  /*
   * "Shifted Tab" is a bit of a mess. Some systems have varying,
   * special keysyms for this symbol. VNC mandates that clients
   * should always send the plain XK_Tab keysym and the server
   * should deduce the meaning based on current Shift state.
   * To comply with this, we will find the keycode that sends
   * XK_Tab, and make sure that Shift isn't cleared. This can
   * possibly result in a different keysym than XK_Tab, but that
   * is the desired behaviour.
   *
   * Note: We never get ISO_Left_Tab here because it's already
   *       been translated in VNCSConnectionST.
   */
  if (keysym == XK_Tab && (state & ShiftMask))
    new_state |= ShiftMask;

  /*
   * We need a bigger state change than just shift,
   * so we need to know what the mask is for level 3 shifts.
   */
  if ((new_state & ~ShiftMask) != (state & ~ShiftMask))
    level_three_mask = GetLevelThreeMask();
  else
    level_three_mask = 0;

  shift_press = level_three_press = 0;

  /* Need a fake press or release of shift? */
  if (!(state & ShiftMask) && (new_state & ShiftMask) && fakeShift) {
    shift_press = PressShift();
    if (shift_press == 0) {
      rfbLog("ERROR: Unable to find modifier key for Shift key press\n");
      return;
    }
    PressKey(kbdDevice, shift_press, TRUE, "temp shift");
  } else if ((state & ShiftMask) && !(new_state & ShiftMask) && fakeShift) {
    int index = 0;
    KeyCode *shift_release = ReleaseShift();
    if (!shift_release) {
      rfbLog("ERROR: Unable to find modifier key(s) for Shift key release\n");
      return;
    }
    while (shift_release[index])
      PressKey(kbdDevice, shift_release[index++], FALSE, "temp shift");
  }

  /* Need a fake press or release of level three shift? */
  if (!(state & level_three_mask) && (new_state & level_three_mask) &&
      fakeShift) {
    level_three_press = PressLevelThree();
    if (level_three_press == 0) {
      rfbLog("ERROR: Unable to find modifier key for ISO_Level3_Shift/Mode_Switch key press\n");
      return;
    }
    PressKey(kbdDevice, level_three_press, TRUE, "temp level 3 shift");
  } else if ((state & level_three_mask) && !(new_state & level_three_mask) &&
             fakeShift) {
    int index = 0;
    level_three_release = ReleaseLevelThree();
    if (!level_three_release) {
      rfbLog("ERROR: Unable to find modifier key(s) for ISO_Level3_Shift/Mode_Switch key release\n");
      return;
    }
    while (level_three_release[index])
      PressKey(kbdDevice, level_three_release[index++], FALSE,
               "temp level 3 shift");
  }

  /* Now press the actual key */
  PressKey(kbdDevice, keycode, TRUE, "keycode");

  /* And store the mapping so that we can do a proper release later */
  for (i = 0; i < 256; i++) {
    if (i == keycode)
      continue;
    if (pressedKeys[i] == keysym) {
      rfbLog("ERROR: Keysym 0x%x generated by both keys %d and %d\n", keysym,
             i, keycode);
      pressedKeys[i] = NoSymbol;
    }
  }

  pressedKeys[keycode] = keysym;

  /* Undo any fake level three shift */
  if (level_three_press != 0)
    PressKey(kbdDevice, level_three_press, FALSE, "temp level 3 shift");
  else if (level_three_release) {
    int index = 0;
    while (level_three_release[index])
      PressKey(kbdDevice, level_three_release[index++], TRUE,
               "temp level 3 shift");
    free(level_three_release);
  }

  /* Undo any fake shift */
  if (shift_press != 0)
    PressKey(kbdDevice, shift_press, FALSE, "temp shift");
  else if (shift_release) {
    int index = 0;
    while (shift_release[index])
      PressKey(kbdDevice, shift_release[index++], TRUE, "temp shift");
    free(shift_release);
  }

  /*
   * When faking a modifier we are putting a keycode (which can
   * currently activate the desired modifier) on the input
   * queue. A future modmap change can change the mapping so
   * that this keycode means something else entirely. Guard
   * against this by processing the queue now.
   */
  mieqProcessInputEvents();
}