summaryrefslogtreecommitdiff
path: root/win/keyedit.cpp
blob: e566496d7976489516e85c86b96c774474a27cbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// keyedit.cpp : implementation file
//

#include "stdafx.h"
#include "leocad.h"
#include "keyedit.h"
#include "keyboard.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CKeyEdit

CKeyEdit::CKeyEdit()
{
	m_Key = 0;
	m_Control = false;
	m_Shift = false;
}

CKeyEdit::~CKeyEdit()
{
}


BEGIN_MESSAGE_MAP(CKeyEdit, CEdit)
	//{{AFX_MSG_MAP(CKeyEdit)
	ON_WM_KEYDOWN()
	ON_WM_KEYUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKeyEdit message handlers

void CKeyEdit::ResetKey()
{
	m_Key = 0;
	m_Control = false;
	m_Shift = false;

	SetWindowText("");
}

void CKeyEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	
	CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CKeyEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{

	CEdit::OnKeyUp(nChar, nRepCnt, nFlags);
}

BOOL CKeyEdit::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message == WM_KEYDOWN)
	{
		// If the keys are for the dialog box or Windows, pass them.
		if ((pMsg->wParam == VK_TAB) || (pMsg->wParam == VK_ESCAPE))
		{
//			DoErasingStuff (hHotKeyEdit);
//			return CEdit::PreTranslateMessage(pMsg);
		}
/*
		else if (pMsg->wParam == VK_BACK && !Control && !Shift)
		{
			// If backspace, then erase the edit control and disable the Assign button.
//			DoErasingStuff (hHotKeyEdit);
//			EnableWindow (GetDlgItem (GetParent (hHotKeyEdit), IDD_INSTALL), FALSE);
			SetWindowText("");

			return true;
		}
*/
		else
		{
			CString Text;

			m_Control = (GetKeyState(VK_CONTROL) < 0);
			m_Shift = (GetKeyState(VK_SHIFT) < 0);

			if (m_Control)
				Text += "Ctrl+";

			if (m_Shift)
				Text += "Shift+";

			const char* KeyName = GetKeyName(pMsg->wParam);

			if (KeyName)
			{
				Text += KeyName;
				m_Key = pMsg->wParam;
			}
			else
			{
				m_Key = 0;
			}

			SetWindowText(Text);

			return true;
		}
	}

	return CEdit::PreTranslateMessage(pMsg);
}