예제 #1
0
// Hook window-key for prevent a window being disabled when window-key pressed.
// To use window-key, save key-state with SetKeyboardState().
static LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode == HC_ACTION && systemKeyDisabled)
    {
        KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
        if (pkbhs->vkCode == VK_LWIN || pkbhs->vkCode == VK_RWIN)
        {
            static BYTE keyState[256];
            // To use window-key as regular key, update keyState.
            if (wParam == WM_KEYDOWN)
            {
                GetKeyboardState(keyState);
                keyState[pkbhs->vkCode] = 0x80;
                SetKeyboardState(keyState);
            }
            else if (wParam == WM_KEYUP)
            {
                GetKeyboardState(keyState);
                keyState[pkbhs->vkCode] = 0x00;
                SetKeyboardState(keyState);
            }
            return 1;
        }
    }
    return CallNextHookEx(keyboardHook, nCode, wParam, lParam);
}
예제 #2
0
static BOOL SendNoControlKey(HWND hWnd, WORD wKey, long lParam)
{
    BYTE pKeys[256];
                  
    GetKeyboardState(&pKeys);
    if (pKeys[VK_CONTROL] & 0x80)
    {
        pKeys[VK_CONTROL] = 0;
        SetKeyboardState(&pKeys);
        SendMessage(hWnd, WM_KEYDOWN, wKey, lParam);
        pKeys[VK_CONTROL] = 0x80;
        SetKeyboardState(&pKeys);
    }
    
    return FALSE;
}
예제 #3
0
/*
 * KeyUpHack:  Due to an apparent bug in Windows, when a key is pressed, NUM LOCK
 *   is toggled, and then the key is released, the key up code is not always the
 *   same as the key down code.  Here we synthesize an up message for the original key;
 *   without this, the key would remain down, causing the player to spin out of control.
 *
 *   vk is the key that was released.
 */
void KeyUpHack(int vk)
{
   int key = 0;
   BYTE keys[NUM_KEYS];

   switch (vk)
   {
   case VK_NUMPAD1:   key = VK_END;        break;
   case VK_NUMPAD2:   key = VK_DOWN;       break;
   case VK_NUMPAD3:   key = VK_NEXT;       break;
   case VK_NUMPAD4:   key = VK_LEFT;       break;
   case VK_NUMPAD5:   key = VK_CLEAR;      break;
   case VK_NUMPAD6:   key = VK_RIGHT;      break;
   case VK_NUMPAD7:   key = VK_HOME;       break;
   case VK_NUMPAD8:   key = VK_UP;         break;
   case VK_NUMPAD9:   key = VK_PRIOR;      break;
   case VK_END:       key = VK_NUMPAD1;    break;
   case VK_DOWN:      key = VK_NUMPAD2;    break;
   case VK_NEXT:      key = VK_NUMPAD3;    break;
   case VK_LEFT:      key = VK_NUMPAD4;    break;
   case VK_CLEAR:     key = VK_NUMPAD5;    break;
   case VK_RIGHT:     key = VK_NUMPAD6;    break;
   case VK_HOME:      key = VK_NUMPAD7;    break;
   case VK_UP:        key = VK_NUMPAD8;    break;
   case VK_PRIOR:     key = VK_NUMPAD9;    break;
   }
   if (key == 0)
      return;

   GetKeyboardState(keys);
   keys[key] = 0;
   SetKeyboardState(keys);
}
예제 #4
0
void CLcInputA::OnReset()
{
	// 키보드는 전부 0
	SetKeyboardState(m_KeyCur);
	
	memset(m_KeyCur, 0, sizeof m_KeyCur);
	memset(m_KeyOld, 0, sizeof m_KeyOld);
	memset(m_KeyMap, 0, sizeof m_KeyMap);
	
	memset(m_BtnCur, 0, sizeof m_BtnCur);
	memset(m_BtnOld, 0, sizeof m_BtnOld);
	memset(m_BtnMap, 0, sizeof m_BtnMap);

	// 마우스는 현재 위치 유지
	m_fWheel = 0;

	POINT	pt;

	::GetCursorPos(&pt);
	::ScreenToClient( m_hWnd, &pt);

	m_vMsCur[0] = FLOAT(pt.x);
	m_vMsCur[1] = FLOAT(pt.y);
	m_vMsCur[2] = 0.f;

	memcpy(m_vMsOld, m_vMsCur, sizeof m_vMsCur);
	memset(m_vDelta,        0, sizeof m_vDelta);
}
예제 #5
0
파일: trace.c 프로젝트: mingpen/OpenNT
void far pascal zSetKeyboardState( BYTE far* pp1 )
{

    SaveRegs();
    /*
    ** Log IN Parameters (No Create/Destroy Checking Yet!)
    */
    LogIn( (LPSTR)"APICALL:SetKeyboardState FixedString+",
        pp1, (DWORD) 256 );

    /*
    ** Call the API!
    */
    RestoreRegs();
    GrovelDS();
    SetKeyboardState(pp1);
    UnGrovelDS();
    SaveRegs();
    /*
    ** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!)
    */
    LogOut( (LPSTR)"APIRET:SetKeyboardState +",
        (short)0 );

    RestoreRegs();
    return;
}
예제 #6
0
파일: gtkbstat.c 프로젝트: ggargano/hbtest2
void hb_gt_winapi_setKbdState( int iKbdState )
{
   BYTE kbState[ 256 ];

   GetKeyboardState( kbState );

   kbState[ VK_SHIFT ]   = ( iKbdState & HB_GTI_KBD_SHIFT ) ? 0x80 : 0;
   kbState[ VK_CONTROL ] = ( iKbdState & HB_GTI_KBD_CTRL ) ? 0x80 : 0;
   kbState[ VK_MENU ]    = ( iKbdState & HB_GTI_KBD_ALT ) ? 0x80 : 0;
   kbState[ VK_LWIN ]    = ( iKbdState & HB_GTI_KBD_LWIN ) ? 0x80 : 0;
   kbState[ VK_RWIN ]    = ( iKbdState & HB_GTI_KBD_RWIN ) ? 0x80 : 0;
   kbState[ VK_APPS ]    = ( iKbdState & HB_GTI_KBD_MENU ) ? 0x80 : 0;
   kbState[ VK_SCROLL ]  = ( iKbdState & HB_GTI_KBD_SCROLOCK ) ? 0x01 : 0;
   kbState[ VK_NUMLOCK ] = ( iKbdState & HB_GTI_KBD_NUMLOCK ) ? 0x01 : 0;
   kbState[ VK_CAPITAL ] = ( iKbdState & HB_GTI_KBD_CAPSLOCK ) ? 0x01 : 0;
   kbState[ VK_INSERT ]  = ( iKbdState & HB_GTI_KBD_INSERT ) ? 0x01 : 0;

   kbState[ VK_LSHIFT ]   = ( iKbdState & HB_GTI_KBD_LSHIFT ) ? 0x80 : 0;
   kbState[ VK_RSHIFT ]   = ( iKbdState & HB_GTI_KBD_RSHIFT ) ? 0x80 : 0;
   kbState[ VK_LCONTROL ] = ( iKbdState & HB_GTI_KBD_LCTRL ) ? 0x80 : 0;
   kbState[ VK_RCONTROL ] = ( iKbdState & HB_GTI_KBD_RCTRL ) ? 0x80 : 0;
   kbState[ VK_LMENU ]    = ( iKbdState & HB_GTI_KBD_LALT ) ? 0x80 : 0;
   kbState[ VK_RMENU ]    = ( iKbdState & HB_GTI_KBD_RALT ) ? 0x80 : 0;

   SetKeyboardState( kbState );
}
예제 #7
0
/*
 * KeyInitHack:  Set number pad keys to be up, otherwise we can get the num lock
 *   bug described above.
 */
void KeyInitHack(void)
{
   BYTE keys[NUM_KEYS];

   GetKeyboardState(keys);
   keys[VK_END] = 0;
   keys[VK_DOWN] = 0;
   keys[VK_NEXT] = 0;
   keys[VK_LEFT] = 0;
   keys[VK_CLEAR] = 0;
   keys[VK_RIGHT] = 0;
   keys[VK_HOME] = 0;
   keys[VK_UP] = 0;
   keys[VK_PRIOR] = 0;
   keys[VK_NUMPAD1] = 0;
   keys[VK_NUMPAD2] = 0;
   keys[VK_NUMPAD3] = 0;
   keys[VK_NUMPAD4] = 0;
   keys[VK_NUMPAD5] = 0;
   keys[VK_NUMPAD6] = 0;
   keys[VK_NUMPAD7] = 0;
   keys[VK_NUMPAD8] = 0;
   keys[VK_NUMPAD9] = 0;
   SetKeyboardState(keys);
}
예제 #8
0
void key_turn_on_numlock()
{
#ifdef _WIN32
	unsigned char keys[256];
	GetKeyboardState(keys);
	keys[VK_NUMLOCK] = 1;
	SetKeyboardState(keys);
#endif
}
예제 #9
0
파일: Map.c 프로젝트: mike2718/WinVi
static VOID KeyState(BYTE VKey, BOOL Down)
{	BYTE AllStates[256];
	BYTE Value = Down ? 0x80 : 0;

	if (GetKeyboardState(AllStates)) {
		AllStates[VKey] = (AllStates[VKey] & ~0x80) | Value;
		SetKeyboardState(AllStates);
	}
}
예제 #10
0
파일: logger.c 프로젝트: g5tyl3/Timber
DWORD WINAPI KeyCapThread(LPVOID param)
{
	MSG msg;
	BYTE keytbl[256];
	int i;
	HMODULE g_module=NULL;

	for(i=0;i<256;i++) keytbl[i]=0;
					
	g_hLastFocus=NULL;
	
	g_module=GetModuleHandle(NULL);

	g_hCapFile=CreateFile((wchar_t *)param,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,NULL);
	if(g_hCapFile==INVALID_HANDLE_VALUE) {
		return -1;
	}
	SetFilePointer(g_hCapFile,0,NULL,FILE_END);

	g_hLogHook=SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,g_module,0);

	if(g_hLogHook==NULL) {
		CloseHandle(g_hCapFile);
		g_hCapFile=NULL;
		return -1;
	}

	g_bLogging=TRUE;
	
	while(g_bLogging) {
		GetMessage(&msg,NULL,0,0);
		if(msg.message==WM_CANCELJOURNAL) {
			
			SetKeyboardState(keytbl);
			g_hLogHook=SetWindowsHookEx(WH_JOURNALRECORD,JournalLogProc,g_module,0);
			
			if(g_hLogHook==NULL) {
				CloseHandle(g_hCapFile);
				g_hCapFile=NULL;
				return -1;
			}
		} else {
			DispatchMessage(&msg);
		}

	}
	
	UnhookWindowsHookEx(g_hLogHook);
	
	CloseHandle(g_hCapFile);
	g_hCapFile=NULL;
	g_hKeyCapThread=NULL;
	
	return 0;
}
예제 #11
0
PUBLIC void
ROMlib_set_caps_lock_off (void)
{
  if (GetKeyState (VK_CAPITAL) & 1)
    {
      char state[256];

      GetKeyboardState (state);
      state[VK_CAPITAL] = 0;
      SetKeyboardState (state);
    }
}
예제 #12
0
CGameInput::CGameInput()
{
	m_hWnd = NULL;

	memset(m_KeyCur, 0, 256);
	memset(m_KeyOld, 0, 256);
	memset(m_MouseCur, 0, 16);
	memset(m_MouseOld, 0, 16);

	m_MousePos=D3DXVECTOR3(0,0,0);
	m_fWheel =0;
	

	BYTE Key[256]={0};
	SetKeyboardState(Key);
	//memset(m_Keyboard,0,sizeof m_Keyboard);
	//memset(m_Mouse,0,sizeof m_Mouse);
}
예제 #13
0
void HS_SendKeys::ResolveKeyModifiers(UINT vkres)
{
	// Examine the vkres code and see what state modifiers it is requesting
	if ( (vkres & 0x0200)  ) 					// CTRL required?
		m_nKeyMod |= CTRLMOD;

	if ( (vkres & 0x0400) )						// ALT required?
		m_nKeyMod |= ALTMOD;

	if ( (vkres & 0x0100) )						// SHIFT required?
		m_nKeyMod |= SHIFTMOD;

	// if we have permanent key down situation, we don't want to press those
	// keys again so we remove that key!

	if ( (m_nKeyMod & CTRLMOD) && (m_nKeyMod & CTRLPERMMOD) )
		m_nKeyMod ^= CTRLMOD;					// remove ctrl flag

	if ( (m_nKeyMod & ALTMOD) && (m_nKeyMod & ALTPERMMOD) )
		m_nKeyMod ^= ALTMOD;					// remove alt flag

	if ( (m_nKeyMod & SHIFTMOD) && (m_nKeyMod & SHIFTPERMMOD) )
		m_nKeyMod ^= SHIFTMOD;					// remove shift flag

	if ( (m_nKeyMod & LWINMOD) && (m_nKeyMod & LWINPERMMOD) )
		m_nKeyMod ^= LWINMOD;					// remove left win flag

#ifdef _DEBUG
	Util_DebugMsg("==> HS_SendKeys::ResolveKeyModifiers : vkres=%d, m_nKeyMod=%d)\n", vkres, m_nKeyMod);
#endif

	// Now check the physical state (as best as the buggy API lets us) to see if any
	// of the modifier keys are held down.  If they are - and none of the CTRLPER type
	// flags are used then force them to be released - even if our next keypress is
	// going to use the same modifier - it's just not close to reliable that way
	// This is not perfect, and if the user continues to twat around it will fail
	if (m_hWnd)
	{
		BYTE	KeybdState[256];

		GetKeyboardState((LPBYTE)&KeybdState);

		// In sendTo mode just make sure that the new keyboard state has all the mods
		// reset unless they are perm on
		if (!(m_nKeyMod & CTRLPERMMOD))
			KeybdState[VK_CONTROL] = 0x00;
		if (!(m_nKeyMod & ALTPERMMOD))
			KeybdState[VK_MENU] = 0x00;
		if (!(m_nKeyMod & SHIFTPERMMOD))
			KeybdState[VK_SHIFT] = 0x00;
		if (!(m_nKeyMod & LWINPERMMOD))
			KeybdState[VK_LWIN] = 0x00;

		SetKeyboardState((LPBYTE)&KeybdState);
	}
	else
	{
		// keybd_event() mode
		if ( IsPhysicallyDown(VK_CONTROL) && (!(m_nKeyMod & CTRLPERMMOD)) )
		{
			SimKeyUp(VK_CONTROL);
			DoKeyDelay();
		}

		if ( IsPhysicallyDown(VK_MENU) && (!(m_nKeyMod & ALTPERMMOD)) )
		{
			SimKeyUp(VK_MENU);
			DoKeyDelay();
		}

		if ( IsPhysicallyDown(VK_SHIFT) && (!(m_nKeyMod & SHIFTPERMMOD)) )
		{
			SimKeyUp(VK_SHIFT);
			DoKeyDelay();
		}

		if ( IsPhysicallyDown(VK_LWIN) && (!(m_nKeyMod & LWINPERMMOD)) )
		{
			SimKeyUp(VK_LWIN);
			DoKeyDelay();
		}
	}

} // ResolveKeyModifiers()
예제 #14
0
LRESULT WINAPI 
SendMailToolbarWndProc(	HWND hwnd, 
						UINT msg, 
						WPARAM wParam, 
						LPARAM lParam)
{
	WNDPROC lpOldProc;

	lpOldProc = (WNDPROC)GetProp( hwnd, "oldproc" );
   
	switch(msg)
	{
		case WM_DESTROY:   
		{
			//  Put back old window proc and
			SetWindowLong( hwnd, GWL_WNDPROC, (DWORD)lpOldProc );

			// remove window property
			RemoveProp( hwnd, "oldproc" ); 
			break;
		}

		case WM_NOTIFY:
		{
			static char szTooltip[256] = {0x00};
			LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT) lParam;;

			switch (((LPNMHDR)lParam)->code)
			{
				case TTN_NEEDTEXTA:
				{
					if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && 
						lpToolTipText->hdr.idFrom <= IDC_MIME )
					{
						int StringId =	lpToolTipText->hdr.idFrom -  
										WM_USER - 1000;

						LoadString (g_hinst, 
									StringId,
									szTooltip,
									sizeof(szTooltip));

						lpToolTipText->lpszText = szTooltip;

						if(g_hwndEudoraStatusbar)
						{
							SendMessage(g_hwndEudoraStatusbar,
										SB_SETTEXT,
										(WPARAM)0,
										(LPARAM)szTooltip);
						}
					
						return 0;
					}
				}

				case TTN_NEEDTEXTW:
				{
					static wchar_t wideBuf[256];

					if(lpToolTipText->hdr.idFrom >= IDC_DECRYPT && 
						lpToolTipText->hdr.idFrom <= IDC_MIME )
					{
						int StringId = lpToolTipText->hdr.idFrom -  
										WM_USER - 1000;
					
    					LoadString (g_hinst, 
									StringId,
									szTooltip,
									sizeof(szTooltip));

						MultiByteToWideChar(CP_ACP, 
											MB_PRECOMPOSED, 
											szTooltip, 
											-1, 
											wideBuf, 
											256);

						lpToolTipText->lpszText = (char*)wideBuf;

						if(g_hwndEudoraStatusbar)
						{
							SendMessage(g_hwndEudoraStatusbar,
										SB_SETTEXT,
										(WPARAM)0,
										(LPARAM)szTooltip);
						}

						return 0;
					}
				}
			}
			break;
		}
	
		case WM_COMMAND:
		{
			switch(wParam)
			{
				case IDC_SENDMAIL:
				{
					HWND hwndSendToolbar = NULL;
					BOOL bEncrypt = FALSE;
					BOOL bSign = FALSE;
					BOOL bPGPMIME = FALSE;
					BYTE KeyboardStatus[256];
					//char temp[100];

					// Did the user have the shift key pressed 
					// when they sent mail?
					GetKeyboardState( KeyboardStatus );

					// Get our Toolbar
					hwndSendToolbar =  FindWindowEx(hwnd, 
													NULL, 
													"ToolbarWindow32", 
													NULL);

					if(hwndSendToolbar)
					{	
						g_bSendingMail = TRUE;
						g_hwndSendToolbar = hwndSendToolbar;

						// set up the Eudora Plugin Menu correctly
						SendMessage(hwnd, 
									WM_COMMAND, 
									(WPARAM)IDC_PLUGINMENU, 
									0);
						
						// See if the user wants us to use PGPMIME
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_MIME,
										0))
						{
							bPGPMIME = TRUE;
						}

						// See if the user wants us encrypt the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_ENCRYPT,
										0))
						{
							bEncrypt = TRUE;
						}

						// See if the user wants us sign the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_SIGN,
										0))
						{
							bSign = TRUE;
						}
					}
					else
					{
						int err;
						char szMessage[256];
						char szTitle[256];

						LoadString(g_hinst, IDS_E_SENDMAIL, szMessage, 
							sizeof(szMessage));
						LoadString(g_hinst, IDS_E_SENDMAILTITLE, szTitle, 
							sizeof(szTitle));

						err = MessageBox(NULL, 
								szMessage, 
								szTitle,	
								MB_YESNO|MB_ICONSTOP);

						if(err == IDNO)
						{
							return 0;
						}
					}	

					if(!bPGPMIME)
					{
						if(!SendMessage(hwnd, WM_COMMAND, IDC_JUSTDOIT, 0))
						{
							return 0;
						}
						else
						{
							LRESULT lresult;
							BYTE oldKeyboardStatus[256];
							
							GetKeyboardState( oldKeyboardStatus );
							SetKeyboardState( KeyboardStatus );

							lresult =  CallWindowProc(	lpOldProc, 
														hwnd, 
														msg, 
														wParam, 
														lParam );
							
							// reset these keys so they don't "stick"
							oldKeyboardStatus[VK_SHIFT]		= 0;
							oldKeyboardStatus[VK_CONTROL]	= 0;
							oldKeyboardStatus[VK_MENU]		= 0;

							SetKeyboardState( oldKeyboardStatus );

							return lresult;
						}
					}
					
					break;
				}

				case IDC_JUSTDOIT:
				{
					HWND hwndSendToolbar = NULL;
					BOOL bEncrypt = FALSE;
					BOOL bSign = FALSE;
					BOOL bEncryptSuccessful = FALSE;
					HCURSOR hCursor, hOldCursor;
					//char temp[100];

					// Get our Toolbar
					hwndSendToolbar =  FindWindowEx(hwnd, 
													NULL, 
													"ToolbarWindow32", 
													NULL);

					if(hwndSendToolbar)
					{		
						// See if the user wants us encrypt the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_ENCRYPT,
										0))
						{
							bEncrypt = TRUE;
						}

						// See if the user wants us sign the message
						if(SendMessage(	hwndSendToolbar,
										TB_ISBUTTONCHECKED,
										(WPARAM)IDC_SIGN,
										0))
						{
							bSign = TRUE;
						}
					}

					// does the user want us to do anything to the message
					if(bEncrypt || bSign )
					{
						BOOL bSelectedText = FALSE;
						CHARRANGE chRange = {0,0};
						HWND hwndParent = NULL;
						HWND hwndRichEdit = NULL;
						HWND hwndAfxWnd = NULL;
						HWND hwndHeaders = NULL;
						char* pRichEditText = NULL;
						char** pPGPRecipients = NULL;
						long NumAddresses = 0;
						long nChar = 0;
						HEADERDATA hd;

						// zero out HEADERDATA struct
						memset(&hd, 0x00, sizeof(hd));

						// Find the windows we are interested in...
						hwndParent		= GetParent(hwnd);
						hwndAfxWnd		= FindWindowEx(	hwndParent, 
														NULL, 
														"AfxMDIFrame40", 
														NULL);

						if(!hwndAfxWnd) // 3.04 and 3.05 use new mfc versions
						{
							hwndAfxWnd	= FindWindowEx(	hwndParent, 
														NULL, 
														"AfxMDIFrame42", 
									 					NULL);
							if(!hwndAfxWnd) 
							{
								char szMessage[256];

								LoadString(g_hinst, IDS_E_OLDVERSION, 
									szMessage, sizeof(szMessage));

								MessageBox(NULL,
									szMessage,
									0, 
									MB_OK);

								return 0;
							}

						}						

						hwndRichEdit	= FindWindowEx(	hwndAfxWnd, 
														NULL, 
														"RICHEDIT", 
														NULL);

						hwndHeaders		= FindWindowEx(	hwndAfxWnd, 
														NULL, 
														"#32770", //Dialog 
														NULL);

						// See if the user has selected text in the window
						SendMessage(hwndRichEdit,  
									EM_EXGETSEL, 
									(WPARAM)0,
									(LPARAM) 
									&chRange);

						bSelectedText = chRange.cpMax - chRange.cpMin;

						// if not context menu invoked then we don't 
						// want to do selected text. 
						// this will protect users 
						if(lParam != SENT_FROM_CONTEXT_MENU)
						{
							bSelectedText = FALSE;
						}

						if(!bSelectedText)
						{
							RECT rect;

							// there is a bug in the richedit control... 
							// so if there is no selected text click in 
							// the lower right corner real quick to 
							// clear up the bug...

							GetClientRect(hwndRichEdit, &rect);
							SendMessage(hwndRichEdit, 
										WM_LBUTTONDOWN, 
										MK_LBUTTON, 
										MAKELPARAM(rect.right - 5, 
										rect.bottom -5 )); 

							SendMessage(hwndRichEdit, 
										WM_LBUTTONUP, 
										MK_LBUTTON,  
										MAKELPARAM(rect.right - 5 , 
										rect.bottom -5 )); 
						}

						// This could take awhile... give some feedback.
						hCursor = LoadCursor(NULL, IDC_WAIT);
						hOldCursor = SetCursor(hCursor);

						// get text of message
						pRichEditText = GetRichEditContents (	hwndRichEdit, 
																&nChar, 
																FALSE, 
																bSelectedText);

						// get the email headers
						GetEudoraHeaders( hwndHeaders, &hd);

						// now create an appropriate list for pgplib
						NumAddresses = CreateRecipientListFromEudoraHeaders(
														&hd, 
														&pPGPRecipients);

						if( pRichEditText )
						{				
							char* pInAttachments = "";
							char* pOutAttachments = NULL;

							// if context menu invoked then we don't 
							// want to do attachments. 
							if(lParam != SENT_FROM_CONTEXT_MENU)
							{
								pInAttachments = hd.pAttachments;
							}

							// length might have changed
							nChar = strlen(pRichEditText);

							// Encrypt Text
							bEncryptSuccessful = EncryptSignRichEditText(	
															&pRichEditText, 
															&nChar, 
															bEncrypt, 
															bSign, 
															pPGPRecipients, 
															NumAddresses,
															pInAttachments,
															&pOutAttachments);

							if( bEncryptSuccessful )
							{
								SetRichEditContents (	hwndRichEdit, 
														pRichEditText,
														FALSE, 
														bSelectedText);

								if(pOutAttachments)
								{
									// set the attachments
									SetEudoraAttachments(	hwndHeaders, 
															pOutAttachments);

									free(pOutAttachments);
								}
								else
								{
									// Wait for about .5 seconds 
									// so user can see encrypted text...
									Sleep(500);
								}
							}
						}
						
						// want to reset buttons for context menu
						// regardless of success or failure
						if(	bEncryptSuccessful || 
							lParam == SENT_FROM_CONTEXT_MENU)
						{
							// Reset the buttons
							SendMessage(hwndSendToolbar,
										TB_CHECKBUTTON,
										(WPARAM)IDC_ENCRYPT, 
										MAKELPARAM(FALSE,0));
							
							HeapFree(GetProcessHeap(), 0, pRichEditText);
						} 

						// want to reset buttons for context menu
						// regardless of success or failure
						if(	bEncryptSuccessful || 
							lParam == SENT_FROM_CONTEXT_MENU)
						{
							// Reset the buttons
							SendMessage(hwndSendToolbar,
										TB_CHECKBUTTON,
										(WPARAM)IDC_ENCRYPT, 
										MAKELPARAM(FALSE,0));

							SendMessage(hwndSendToolbar,
										TB_CHECKBUTTON,
										(WPARAM)IDC_SIGN,
										MAKELPARAM(FALSE, 0));

							SendMessage(hwndSendToolbar,
										TB_ENABLEBUTTON,
										(WPARAM)IDC_JUSTDOIT,
										MAKELPARAM(FALSE, 0));
						}

						// clean up after ourselves
						FreeRecipientList(pPGPRecipients, NumAddresses);

						FreeHeaderData(&hd);

						SetCursor(hOldCursor);
					}
					else
					{
						// we 'successfully' did nothing to the message
						bEncryptSuccessful = TRUE;
					}

					return bEncryptSuccessful;
					break;
				}

				case IDC_KEYMGR:
				{
					char szPath[MAX_PATH];
					char szPGPkeys[256];
					PGPError error = kPGPError_NoErr;

					LoadString(g_hinst, IDS_PGPKEYSEXE, szPGPkeys,
						sizeof(szPGPkeys));

					error = PGPclGetPath (kPGPclPGPkeysExeFile,
						szPath, sizeof(szPath));

					if( IsntPGPError(error) )
					{
						PGPclExecute (szPath, SW_SHOW);
					}
					else
					{
						char szError[256];

						LoadString(g_hinst, IDS_E_LAUNCHPGPKEYS, szError,
							sizeof(szError));

						MessageBox(NULL, 
							szError, 
							0, 
							MB_OK);
					}
					
					break;
				}
			}
		}
		
		case WM_ENTERIDLE:
		{
			if( g_bSendingMail && g_hwndSendToolbar && wParam == MSGF_MENU )
			{
				g_bInitializeButtons = FALSE;
				g_bSendingMail = FALSE;
				g_hwndSendToolbar = NULL;
				PostMessage(hwnd, WM_KEYDOWN, (WPARAM)VK_ESCAPE, 0x001c0001); 
				PostMessage(hwnd, WM_KEYUP, (WPARAM)VK_ESCAPE, 0x001c0001); 
			}

			break;
		}
	
		case WM_DRAWITEM:
		{
			// control identifier 
			UINT idCtl = (UINT) wParam;	
			// item-drawing information
			LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;  
			//char szString[256] = {0x00};

			if( g_bSendingMail )
			{
				if(lpdis && lpdis->CtlType == ODT_MENU)
				{
					if(*((void**)(lpdis->itemData + 4)))
					{
						WPARAM wCommand = 0;
						BOOL bItemChecked = FALSE;

						// see if it is already checked
						if((lpdis->itemState & ODS_CHECKED)) 
						{
							bItemChecked = TRUE;
						}

						// see which plugin this menuitem represents
						if( !strcmp(*((char**)(lpdis->itemData + 4)), 
										"PGP plugin 1 (use toolbar)") )
						{
							wCommand = IDC_ENCRYPT;

							// we might be getting a window from a cancel...
							if( g_bInitializeButtons && bItemChecked) 
							{
								g_bEncrypt = TRUE;
							}
						}
						else if( !strcmp(*((char**)(lpdis->itemData + 4)), 
											"PGP plugin 2 (use toolbar)") )
						{
							wCommand = IDC_SIGN;

							// we might be getting a window from a cancel...
							if( g_bInitializeButtons && bItemChecked) 
							{
								g_bSign	= TRUE;
							}
						}

						if( !g_bInitializeButtons )
						{
							// make sure the window handle is valid
							if( g_hwndSendToolbar) 
							{
								if( wCommand ) // is this one of our menus
								{
									BOOL bCommandPressed = FALSE;
									BOOL bPGPMIMEPressed = FALSE;

									bCommandPressed = SendMessage(	
														g_hwndSendToolbar, 
														TB_ISBUTTONCHECKED, 
														wCommand, 
														0);

									bPGPMIMEPressed = SendMessage(	
														g_hwndSendToolbar, 
														TB_ISBUTTONCHECKED, 
														IDC_MIME, 
														0);

									if( (bCommandPressed && 
										!bItemChecked && bPGPMIMEPressed) || 
										(bCommandPressed && bItemChecked && 
										!bPGPMIMEPressed) ||
										(!bCommandPressed && bItemChecked))
									{
										SendMessage(hwnd, 
													WM_COMMAND, 
													(WPARAM)lpdis->itemID, 
													0);
									}
								}
							}
						}
					}
				}
			}
			break;
		}
	} 
	
	//  Pass all non-custom messages to old window proc
	return CallWindowProc(lpOldProc, hwnd, msg, wParam, lParam ) ;
}
예제 #15
0
void HS_SendKeys::SimModsDown(void)
{
#ifdef _DEBUG
	Util_DebugMsg("==> HS_SendKeys::SimModsDown : m_nKeyMod=%d)\n", m_nKeyMod);
#endif
	// If the window is NULL use keybd_event
	if (m_hWnd == NULL)
	{
		if ( m_nKeyMod & LWINMOD ) 				// WIN required?
			keybd_event(VK_LWIN, m_scanLWin, 0, 0);
		if ( m_nKeyMod & SHIFTMOD ) 			// SHIFT required?
			keybd_event(VK_SHIFT, m_scanShift, 0, 0);
		if ( m_nKeyMod & CTRLMOD ) 				// CTRL required?
			keybd_event(VK_CONTROL, m_scanCtrl, 0, 0);
		if ( m_nKeyMod & ALTMOD ) 				// ALT required?
			keybd_event(VK_MENU, m_scanAlt, 0, 0);
	}
	else
	{
		LPARAM	lparam;
		BYTE	KeybdState[256];

		GetKeyboardState((LPBYTE)&KeybdState);

		// First alter the keyboard state to match the mods we are about to send
		if ( m_nKeyMod & LWINMOD ) 				// WIN required?
			KeybdState[VK_LWIN] |= 0x80;
		if ( m_nKeyMod & SHIFTMOD ) 			// SHIFT required?
			KeybdState[VK_SHIFT] |= 0x80;
		if ( m_nKeyMod & CTRLMOD ) 				// CTRL required?
			KeybdState[VK_CONTROL] |= 0x80;
		if (m_nKeyMod & ALTMOD)					// ALT required?
			KeybdState[VK_MENU] |= 0x80;

		SetKeyboardState((LPBYTE)&KeybdState);

		// Now send the individual WM_KEY messages
		if ( m_nKeyMod & LWINMOD ) 				// WIN required?
		{
			lparam = 0x00000001 | (LPARAM)(m_scanLWin << 16);
			PostMessage(m_hWnd, WM_KEYDOWN, VK_LWIN, lparam);
		}

		if ( m_nKeyMod & SHIFTMOD ) 			// SHIFT required?
		{
			lparam = 0x00000001 | (LPARAM)(m_scanShift << 16);
			PostMessage(m_hWnd, WM_KEYDOWN, VK_SHIFT, lparam);
		}

		if ( m_nKeyMod & CTRLMOD ) 				// CTRL required?
		{
			lparam = 0x00000001 | (LPARAM)(m_scanCtrl << 16);
			PostMessage(m_hWnd, WM_KEYDOWN, VK_CONTROL, lparam);
		}

		if ( (m_nKeyMod & ALTMOD) && !(m_nKeyMod & CTRLMOD) )	// Alt without Ctrl
		{
			lparam = 0x20000001 | (LPARAM)(m_scanAlt << 16);		// AltDown=1, repeat=1
			PostMessage(m_hWnd, WM_SYSKEYDOWN, VK_MENU, lparam);
		}
		else if (m_nKeyMod & ALTMOD)			// Alt with Ctrl
		{
			lparam = 0x00000001 | (LPARAM)(m_scanAlt << 16);
			PostMessage(m_hWnd, WM_KEYDOWN, VK_MENU, lparam);
		}
	}

	// Key down key delay
	DoKeyDownDelay();

} // SimModsDown()
예제 #16
0
int OnButtonPressed(WPARAM, LPARAM lParam)
{
	CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam;

	int iType;
	if (!mir_strcmp(cbcd->pszModule, "Switch Layout and Send"))
		iType = 1;
	else if (!mir_strcmp(cbcd->pszModule, "Translit and Send"))
		iType = 2;
	else if (!mir_strcmp(cbcd->pszModule, "Invert Case and Send"))
		iType = 3;
	else
		return 0;

	HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE);
	if (!hEdit)
		hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE);

	BYTE byKeybState[256];
	GetKeyboardState(byKeybState);
	byKeybState[VK_CONTROL] = 128;
	SetKeyboardState(byKeybState);
	SendMessage(hEdit, WM_KEYDOWN, VK_UP, 0);
	byKeybState[VK_CONTROL] = 0;
	SetKeyboardState(byKeybState);

	TCHAR *sel = Message_GetFromStream(hEdit, SF_TEXT | SF_UNICODE);
	size_t slen = mir_tstrlen(sel);
	if (slen != 0) {
		switch (iType) {
		case 3: Invert(sel); break;
		case 2: Transliterate(sel); break;
		case 1:
			DWORD dwProcessID;
			DWORD dwThreadID = GetWindowThreadProcessId(cbcd->hwndFrom, &dwProcessID);
			HKL hkl = GetKeyboardLayout(dwThreadID);

			memset(&smgp, 0, sizeof(smgp));
			smgp.cbSize = sizeof(smgp);
			smgp.str = sel;
			smgp.flag = SAFL_TCHAR;

			if (ServiceExists(MS_SMILEYADD_BATCHPARSE))
				smileyPrs = (SMADD_BATCHPARSERES *)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&smgp);

			ActivateKeyboardLayout((HKL)HKL_PREV, KLF_ACTIVATE);

			for (int i = 0; i < (int)slen; i++) {
				TCHAR tchr;
				BYTE keys[256] = { 0 };
				SHORT vks = VkKeyScanEx(sel[i], hkl);

				keys[VK_SHIFT] = (HIBYTE(vks) & 1) ? 0xFF : 0x00; // shift
				keys[VK_CONTROL] = (HIBYTE(vks) & 2) ? 0xFF : 0x00; // ctrl
				keys[VK_MENU] = (HIBYTE(vks) & 4) ? 0xFF : 0x00;	// alt

				if (!isItSmiley(i)) {
					if (ToUnicodeEx(LOBYTE(vks), 0, keys, &tchr, 1, 0, GetKeyboardLayout(dwThreadID)) == 1)
						sel[i] = tchr;
				}
			}
			if (smileyPrs != NULL)
				CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)smileyPrs);
			break;
		}
	}

	ptrT tszSymbol(db_get_tsa(NULL, "TranslitSwitcher", "ResendSymbol"));
	if (tszSymbol == NULL) {
		SetWindowText(hEdit, sel);
		SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
		SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
	}
	else if (_tcsncmp(sel, tszSymbol, mir_tstrlen(tszSymbol)) == 0) {
		SetWindowText(hEdit, sel);
		SendMessage(hEdit, EM_SETSEL, 0, (LPARAM)slen);
		SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
	}
	else {
		CMString tszFinal(FORMAT, _T("%s %s"), tszSymbol, sel);
		SetWindowText(hEdit, tszFinal.GetString());
		SendMessage(hEdit, EM_SETSEL, 0, tszFinal.GetLength());
		SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0);
	}

	mir_free(sel);
	return 1;
}
예제 #17
0
//##ModelId=474D302503BA
void CSendKeys::SendKeyDown(BYTE VKey, WORD NumTimes, bool GenUpMsg, bool bDelay)
{
  WORD Cnt = 0;
  BYTE ScanCode = 0;
  bool NumState = false;

  if (VKey == VK_NUMLOCK)
  {
    DWORD dwVersion = ::GetVersion();

    for (Cnt=1; Cnt<=NumTimes; Cnt++)
    {
      if (bDelay)
        CarryDelay();
      // snippet based on:
      // http://www.codeproject.com/cpp/togglekeys.asp
      if (dwVersion < 0x80000000)
      {
        ::keybd_event(VKey, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
        ::keybd_event(VKey, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
      }
      else
      {
        // Win98 and later
        if ( ((DWORD)(HIBYTE(LOWORD(dwVersion))) >= 10) )
        {
          // Define _WIN32_WINNT > 0x0400
          // to compile
          INPUT input[2] = {0};
          input[0].type = input[1].type = INPUT_KEYBOARD;
          input[0].ki.wVk = input[1].ki.wVk = VKey;
          input[1].ki.dwFlags = KEYEVENTF_KEYUP;
          ::SendInput(sizeof(input) / sizeof(INPUT), input, sizeof(INPUT));
        }
        // Win95
        else
        {
          KEYBOARDSTATE_t KeyboardState;
          NumState = GetKeyState(VK_NUMLOCK) & 1 ? true : false;
          GetKeyboardState(&KeyboardState[0]);
          if (NumState)
            KeyboardState[VK_NUMLOCK] &= ~1;
          else
            KeyboardState[VK_NUMLOCK] |= 1;

          SetKeyboardState(&KeyboardState[0]);
        }
      }
    }
    return;
  }

  // Get scancode
  ScanCode = LOBYTE(::MapVirtualKey(VKey, 0));

  // Send keys
  for (Cnt=1; Cnt<=NumTimes; Cnt++)
  {
    // Carry needed delay ?
    if (bDelay)
      CarryDelay();

    KeyboardEvent(VKey, ScanCode, IsVkExtended(VKey) ? KEYEVENTF_EXTENDEDKEY : 0);
    if (GenUpMsg)
      KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP);
  }
}
예제 #18
0
void HS_SendKeys::SimModsUp(void)
{
#ifdef _DEBUG
	Util_DebugMsg("==> HS_SendKeys::SimModsUp : m_nKeyMod=%d)\n", m_nKeyMod);
#endif
	// If the window is NULL use keybd_event
	if (m_hWnd == NULL)
	{
		if ( m_nKeyMod & ALTMOD ) 				// ALT required?
			keybd_event(VK_MENU, m_scanAlt, KEYEVENTF_KEYUP, 0);
		if ( m_nKeyMod & CTRLMOD ) 				// CTRL required?
			keybd_event(VK_CONTROL, m_scanCtrl, KEYEVENTF_KEYUP, 0);
		if ( m_nKeyMod & SHIFTMOD ) 			// SHIFT required?
			keybd_event(VK_SHIFT, m_scanShift, KEYEVENTF_KEYUP, 0);
		if ( m_nKeyMod & LWINMOD ) 				// WIN required?
			keybd_event(VK_LWIN, m_scanLWin, KEYEVENTF_KEYUP, 0);
	}
	else
	{
		LPARAM	lparam;
		BYTE	KeybdState[256];

		GetKeyboardState((LPBYTE)&KeybdState);

		if ( (m_nKeyMod & ALTMOD) && !(m_nKeyMod & CTRLMOD) )	// Alt without Ctrl
		{
			lparam = 0xE0000001 | (LPARAM)(m_scanAlt << 16);	// AltDown=1, Repeat=1, Key = up
			PostMessage(m_hWnd, WM_SYSKEYUP, VK_MENU, lparam);
		}
		else if (m_nKeyMod & ALTMOD)			// Alt with Ctrl
		{
			lparam = 0xC0000001 | (LPARAM)(m_scanAlt << 16);
			PostMessage(m_hWnd, WM_KEYUP, VK_MENU, lparam);
		}

		if ( m_nKeyMod & CTRLMOD ) 				// CTRL required?
		{
			lparam = 0xC0000001 | (LPARAM)(m_scanCtrl << 16);
			PostMessage(m_hWnd, WM_KEYUP, VK_CONTROL, lparam);
		}

		if ( m_nKeyMod & SHIFTMOD ) 			// SHIFT required?
		{
			lparam = 0xC0000001 | (LPARAM)(m_scanShift << 16);
			PostMessage(m_hWnd, WM_KEYUP, VK_SHIFT, lparam);
		}

		if ( m_nKeyMod & LWINMOD ) 				// WIN required?
		{
			lparam = 0xC0000001 | (LPARAM)(m_scanLWin << 16);
			PostMessage(m_hWnd, WM_KEYUP, VK_LWIN, lparam);
		}

		// Now alter the keyboard state to match the mods we just sent
		if ( m_nKeyMod & LWINMOD ) 				// WIN required?
			KeybdState[VK_LWIN] ^= 0x80;
		if ( m_nKeyMod & SHIFTMOD ) 			// SHIFT required?
			KeybdState[VK_SHIFT] ^= 0x80;
		if ( m_nKeyMod & CTRLMOD ) 				// CTRL required?
			KeybdState[VK_CONTROL] ^= 0x80;
		if (m_nKeyMod & ALTMOD)					// ALT required?
			KeybdState[VK_MENU] ^= 0x80;

		SetKeyboardState((LPBYTE)&KeybdState);
	}

	// Key up keydelay
	DoKeyDelay();

} // SimModsUp()
예제 #19
0
//-------------------------------------------------
// temporarily release control keys (CTRL, ALT, SHIFT)
// release = 1: release
// release = 0: change control keys to their original state
//-------------------------------------------------
void ReleaseControlKeys(int release)
{
	static BYTE ctrl = 0;
	static BYTE lctrl = 0;
	static BYTE rctrl = 0;

	static BYTE alt = 0;
	static BYTE lalt = 0;
	static BYTE ralt = 0;

	static BYTE sh = 0;
	static BYTE lsh = 0;
	static BYTE rsh = 0;


	static int TempReleased = 0;

	if (release) {
		ctrl = KeyState[VK_CONTROL];
		lctrl = KeyState[VK_LCONTROL];
		rctrl = KeyState[VK_RCONTROL];

		sh = KeyState[VK_SHIFT];
		lsh = KeyState[VK_LSHIFT];
		rsh = KeyState[VK_RSHIFT];

		alt = KeyState[VK_MENU];
		lalt = KeyState[VK_LMENU];
		ralt = KeyState[VK_RMENU];

		KeyState[VK_CONTROL] = 0;
		KeyState[VK_LCONTROL] = 0;
		KeyState[VK_RCONTROL] = 0;

		KeyState[VK_SHIFT] = 0;
		KeyState[VK_LSHIFT] = 0;
		KeyState[VK_RSHIFT] = 0;

		KeyState[VK_MENU] = 0;
		KeyState[VK_LMENU] = 0;
		KeyState[VK_RMENU] = 0;

		SetKeyboardState(KeyState);
		TempReleased = 1;
	}
	else if (TempReleased) {
		TempReleased = 0;

		KeyState[VK_CONTROL] = ctrl;
		KeyState[VK_LCONTROL] = lctrl;
		KeyState[VK_RCONTROL] = rctrl;

		KeyState[VK_SHIFT] = sh;
		KeyState[VK_LSHIFT] = lsh;
		KeyState[VK_RSHIFT] = rsh;

		KeyState[VK_MENU] = alt;
		KeyState[VK_LMENU] = lalt;
		KeyState[VK_RMENU] = ralt;

		SetKeyboardState(KeyState);
	}
}