Click here to Skip to main content
15,892,298 members
Articles / Desktop Programming / MFC

CKeystrokeEngine

Rate me:
Please Sign up or sign in to vote.
4.98/5 (30 votes)
21 Jun 2004CPOL4 min read 303K   7.7K   108  
A set of classes used to send keystrokes to a selected window
// KeyTestDlg.h : header file
//

#if !defined(AFX_KEYTESTDLG_H__81E4693D_EED1_49AD_B413_4EA3835035A2__INCLUDED_)
#define AFX_KEYTESTDLG_H__81E4693D_EED1_49AD_B413_4EA3835035A2__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "DialogHeaderCtrl.h"
#include "afxwin.h"
#include "MiscCtrls.h"

#define IDC_SKEYS						WM_USER+1901
#define IDC_SACTIONS                    WM_USER+1902
#define IDC_MKEYS                       WM_USER+1903
#define IDC_SKEY_CTRL                   WM_USER+1904
#define IDC_SKEY_ALT                    WM_USER+1905
#define IDC_SKEY_SHIF                   WM_USER+1906
#define IDC_SKEY_CTRLALT                WM_USER+1907
#define IDC_SKEY_CTRLSHIFT              WM_USER+1908
#define IDC_SKEY_ALTSHIFT               WM_USER+1909
#define IDC_SKEY_CTRLALTSHIFT           WM_USER+1910
#define IDC_SKEY_SHIFT                  WM_USER+1911
#define IDC_SKEY_ESC                    WM_USER+1912
#define IDC_SKEY_TAB                    WM_USER+1913
#define IDC_SKEY_BACK                   WM_USER+1914
#define IDC_SKEY_INS                    WM_USER+1915
#define IDC_SKEY_DEL                    WM_USER+1916
#define IDC_SKEY_F1                     WM_USER+1917
#define IDC_SKEY_F2                     WM_USER+1918
#define IDC_SKEY_F3                     WM_USER+1919
#define IDC_SKEY_F4                     WM_USER+1920
#define IDC_SKEY_F5                     WM_USER+1921
#define IDC_SKEY_F6                     WM_USER+1922
#define IDC_SKEY_F7                     WM_USER+1923
#define IDC_SKEY_F8                     WM_USER+1924
#define IDC_SKEY_F9                     WM_USER+1925
#define IDC_SKEY_F10                    WM_USER+1926
#define IDC_SKEY_F11                    WM_USER+1927
#define IDC_SKEY_F12                    WM_USER+1928
#define IDC_SKEY_ENTER                  WM_USER+1929
#define IDC_SKEY_HOME                   WM_USER+1930
#define IDC_SKEY_END                    WM_USER+1931
#define IDC_SKEY_CAPSLOCK               WM_USER+1932
#define IDC_SKEY_NUMLOCK                WM_USER+1933
#define IDC_SKEY_SCROLLLOCK             WM_USER+1934
#define IDC_SKEY_UP                     WM_USER+1935
#define IDC_SKEY_DOWN                   WM_USER+1936
#define IDC_SKEY_LEFT                   WM_USER+1937
#define IDC_SKEY_RIGHT                  WM_USER+1938
#define IDC_SKEY_PAUSE                  WM_USER+1939
#define IDC_SKEY_PAGEUP                 WM_USER+1940
#define IDC_SKEY_PAGEDOWN               WM_USER+1941
#define IDC_SKEY_PRINTSCRN              WM_USER+1942
#define IDC_SKEY_NUMPAD0                WM_USER+1943
#define IDC_SKEY_NUMPAD1                WM_USER+1944
#define IDC_SKEY_NUMPAD2                WM_USER+1945
#define IDC_SKEY_NUMPAD3                WM_USER+1946
#define IDC_SKEY_NUMPAD4                WM_USER+1947
#define IDC_SKEY_NUMPAD5                WM_USER+1948
#define IDC_SKEY_NUMPAD6                WM_USER+1949
#define IDC_SKEY_NUMPAD7                WM_USER+1950
#define IDC_SKEY_NUMPAD8                WM_USER+1951
#define IDC_SKEY_NUMPAD9                WM_USER+1952
#define IDC_SKEY_LWIN                   WM_USER+1953
#define IDC_SKEY_RWIN                   WM_USER+1954
#define IDC_SKEY_APPS                   WM_USER+1955
#define IDC_SKEY_CAPSLOCKON             WM_USER+1956
#define IDC_SKEY_CAPSLOCKOFF            WM_USER+1957
#define IDC_SKEY_NUMLOCKON              WM_USER+1958
#define IDC_SKEY_NUMLOCKOFF             WM_USER+1959
#define IDC_SKEY_SCROLLLOCKON           WM_USER+1960
#define IDC_SKEY_SCROLLLOCKOFF          WM_USER+1961
#define IDC_SKEY_REPEAT			        WM_USER+1962
#define IDC_SKEY_SDATE			        WM_USER+1963
#define IDC_SKEY_LDATE			        WM_USER+1964
#define IDC_SKEY_TIME12			        WM_USER+1965
#define IDC_SKEY_TIME24			        WM_USER+1966
#define IDC_SKEY_DELAY			        WM_USER+1967
#define IDC_SKEY_VARIABLE		        WM_USER+1968
#define IDC_SKEY_FORMATDATETIME         WM_USER+1969
#define IDC_SKEY_CTRLLOCK				WM_USER+1970
#define IDC_SKEY_CTRLUNLOCK				WM_USER+1971
#define IDC_SKEY_ALTLOCK				WM_USER+1972
#define IDC_SKEY_ALTUNLOCK				WM_USER+1973
#define IDC_SKEY_SHIFTLOCK				WM_USER+1974
#define IDC_SKEY_SHIFTUNLOCK			WM_USER+1975

/////////////////////////////////////////////////////////////////////////////
// CKeyTestDlg dialog

class CKeyTestDlg : public CDialog
{
// Construction
public:
	CKeyTestDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	//{{AFX_DATA(CKeyTestDlg)
	enum { IDD = IDD_KEYTEST_DIALOG };
		// NOTE: the ClassWizard will add data members here
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CKeyTestDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL

// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	//{{AFX_MSG(CKeyTestDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	afx_msg void OnSendkeys();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

public:
	BOOL m_bAddPause;
	CString m_sKeys;
	CEdit m_ctrlPause;
	UINT m_nPause;
	BOOL m_bTranspose;
	BOOL m_bSendToWnd;
	CButton m_ctrlWndTitle;
	CButton m_ctrlWndClass;
	CEdit m_ctrlWndTitleEdit;
	CEdit m_ctrlWndClassEdit;
	CListBox m_ctrlWndList;
	CButton m_ctrlExact;
	CButton m_ctrlCaseSensitive;
	CButton m_ctrlReActivate;
	CEdit m_ctrlReActivateEdit;
	afx_msg void OnBnClickedCaddpause();
	afx_msg void OnBnClickedReactivate();
	afx_msg void OnBnClickedSendtownd();
	afx_msg void OnBnClickedCheckTitle();
	afx_msg void OnBnClickedCheckClass();
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR *lpMMI);
	CDialogHeaderCtrl m_HeaderCtrl;
protected:
	virtual void OnOK();
	
	void StartLooking(void);
	void StopLooking(void);
	HWND SmallestWindowFromPoint(const POINT point);
	void InvertBorder(const HWND hWnd);
	void OnAlwaysOnTop();
	void Scan(CPoint point);
	
	// Since ScanEx is async, these hold data we need later
	HWND m_hWndScanEx;
	CPoint m_ptScanEx;
	
	bool m_bIsLooking, m_bAlwaysOnTop, m_bScanEx;
	HICON m_hIconScan;
	HCURSOR m_hCursorScan, m_hCursorPrev;
	HWND m_hWndPrev;
	int m_nScanLevel;
	
	CCoolBtn	m_bSpecialKeys;
	CCoolBtn	m_bMoreKeys;
	CCoolBtn	m_bSpecialActions;
	
public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	CStatic m_ctrlLook;
	BOOL m_bWndTitle;
	BOOL m_bWndClass;
	BOOL m_bExact;
	BOOL m_bCaseSensitive;
	BOOL m_bReActivate;
	afx_msg void OnLbnDblclkList1();
	UINT m_nReActivate;
	CEdit m_ctrlKeys;
	CButton m_ctrlTranspose;
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_KEYTESTDLG_H__81E4693D_EED1_49AD_B413_4EA3835035A2__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions