#include "StdAfx.h"
#include "BKKbdButn.h"
#include "BK.h"
#include "Defines.h"

CBKKbdButn::CBKKbdButn(UINT nID)
	: m_cx(0)
	, m_cy(0)
	, m_nKbdBitMapLeft(0)
	, m_nKbdBitmapTop(0)
	, m_nIdx(-1)
	, m_nArraySize(-1)
	, m_bAR2Pressed(FALSE)
	, m_bSUPressed(FALSE)
	, m_bLShiftPressed(FALSE)
	, m_bRShiftPressed(FALSE)
	, m_bIsZag(TRUE)
	, m_bControlKeyPressed(FALSE)
	, m_bRegularKeyPressed(FALSE)
	, m_pBKKeyboardArray(NULL)
{
	switch (nID)
	{
		case IDB_BITMAP_SOFT:
			m_pBKKeyboardArray = (BKKey *)m_ButnKbdKeys;
			break;

		case IDB_BITMAP_PLEN:
			m_pBKKeyboardArray = (BKKey *)m_PlenKbdKeys;
			break;

		default:
			return;
	}

	m_hBmp = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(nID));

	if (m_hBmp)
	{
		BITMAP bitmap;
		VERIFY(::GetObject(m_hBmp, sizeof(BITMAP), &bitmap));
		m_cx = (int) bitmap.bmWidth;
		m_cy = (int) bitmap.bmHeight;
	}

	m_nArraySize = GetArraySize();
	m_nAR2Index = GetKeyIndexById(BKKEY_ALT);
	m_nSUIndex = GetKeyIndexById(BKKEY_CTRL);
	m_nLShiftIndex = GetKeyIndexById(BKKEY_LSHIFT);
	m_nRShiftIndex = GetKeyIndexById(BKKEY_RSHIFT);
	m_brsh = CreateHatchBrush(HS_DIAGCROSS, RGB(0xc0, 0xc0, 0xc0));
	m_pen = CreatePen(PS_DOT, 0, RGB(0xc0, 0xc0, 0xc0));
}


CBKKbdButn::~CBKKbdButn(void)
{
	if (m_hBmp)
	{
		DeleteObject(m_hBmp);
		m_hBmp = NULL;
	}

	if (m_brsh)
	{
		DeleteObject(m_brsh);
	}

	if (m_pen)
	{
		DeleteObject(m_pen);
	}
}

BEGIN_MESSAGE_MAP(CBKKbdButn, CWnd)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
END_MESSAGE_MAP()


void CBKKbdButn::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	HDC hdcMem = CreateCompatibleDC(dc.GetSafeHdc());
	HGDIOBJ hOldBitmap = SelectObject(hdcMem, m_hBmp);
	BitBlt(dc.GetSafeHdc(), m_nKbdBitMapLeft, m_nKbdBitmapTop, m_cx, m_cy, hdcMem, 0, 0, SRCCOPY);
	SelectObject(hdcMem, hOldBitmap);
	DeleteDC(hdcMem);
}



void CBKKbdButn::OnLButtonDown(UINT nFlags, CPoint point)
{
	BYTE nScanCode = 0;
	BYTE nInt = 0;
	m_nIdx = GetKeyIndex(point.x, point.y);

	if (m_nIdx >= 0)
	{
		BKKey *pKey = m_pBKKeyboardArray + (DWORD_PTR)m_nIdx;

		if (pKey->nType != BKKEY_RESERVED)
		{
			SetCapture();
			FocusPressedkey(m_nIdx);
			LPARAM lParam = 0;

			switch (pKey->nType)
			{
				case BKKEY_ALT:
					m_bControlKeyPressed = TRUE;
					m_bAR2Pressed = TRUE;
					break;

				case BKKEY_CTRL:
					m_bControlKeyPressed = TRUE;
					m_bSUPressed = TRUE;
					break;

				case BKKEY_LSHIFT:
					m_bControlKeyPressed = TRUE;
					m_bLShiftPressed = TRUE;
					break;

				case BKKEY_RSHIFT:
					m_bControlKeyPressed = TRUE;
					m_bRShiftPressed = TRUE;
					break;

				case BKKEY_ZAGL:
					m_bIsZag = TRUE;
					break;

				case BKKEY_STR:
					m_bIsZag = FALSE;
					break;

				case BKKEY_REGULAR:
					m_bRegularKeyPressed = TRUE;
					nScanCode = TranslateScanCode(pKey->nScanCode);
					nInt = (m_bAR2Pressed) ? INTERRUPT_274 : pKey->nInt;
					lParam = (nInt << 8) + nScanCode;
					break;
			}

			theApp.GetMainWnd()->SendMessage(WM_VKBD_DOWN, pKey->nType, lParam);
		}
	}

	CWnd::OnLButtonDown(nFlags, point);
}

BYTE CBKKbdButn::TranslateScanCode(BYTE nScanCode)
{
	if (m_bSUPressed)
	{
		if ((0100 <= nScanCode) && (nScanCode <= 0137))
		{
			return nScanCode & 037;
		}
	}

	if (m_bLShiftPressed || m_bRShiftPressed)
	{
		if ((054 <= nScanCode) && (nScanCode <= 047))
		{
			return nScanCode + 020;
		}
		else if ((060 <= nScanCode) && (nScanCode <= 073))
		{
			return nScanCode - 020;
		}
	}

	if (!m_bIsZag)
	{
		if ((0100 <= nScanCode) && (nScanCode <= 0137))
		{
			if (m_bLShiftPressed || m_bRShiftPressed)
			{
				return nScanCode;
			}
			else
			{
				return nScanCode | 040;
			}
		}
	}

	return nScanCode;
}

void CBKKbdButn::OnLButtonUp(UINT nFlags, CPoint point)
{
	if (m_nIdx >= 0)
	{
		BKKey *pKey = m_pBKKeyboardArray + (DWORD_PTR)m_nIdx;

		if (pKey->nType != BKKEY_RESERVED)
		{
			ReleaseCapture();

			if (m_bControlKeyPressed)
			{
				if (m_bRegularKeyPressed)
				{
					m_bControlKeyPressed = FALSE;

					if (m_bAR2Pressed)
					{
						m_bAR2Pressed = FALSE;
						UnFocusPressedkey(m_nAR2Index);
						theApp.GetMainWnd()->SendMessage(WM_VKBD_UP, BKKEY_ALT, 0);
					}

					if (m_bSUPressed)
					{
						m_bSUPressed = FALSE;
						UnFocusPressedkey(m_nSUIndex);
						theApp.GetMainWnd()->SendMessage(WM_VKBD_UP, BKKEY_CTRL, 0);
					}

					if (m_bLShiftPressed)
					{
						m_bLShiftPressed = FALSE;
						UnFocusPressedkey(m_nLShiftIndex);
						theApp.GetMainWnd()->SendMessage(WM_VKBD_UP, BKKEY_LSHIFT, 0);
					}

					if (m_bRShiftPressed)
					{
						m_bRShiftPressed = FALSE;
						UnFocusPressedkey(m_nRShiftIndex);
						theApp.GetMainWnd()->SendMessage(WM_VKBD_UP, BKKEY_RSHIFT, 0);
					}

					goto lbl_keyup;
				}
			}
			else
			{
lbl_keyup:      UnFocusPressedkey(m_nIdx);
				theApp.GetMainWnd()->SendMessage(WM_VKBD_UP, pKey->nType, 0);
			}

			if (m_bRegularKeyPressed)
			{
				m_bRegularKeyPressed = FALSE;
			}
		}

		m_nIdx = -1;
	}

	CWnd::OnLButtonUp(nFlags, point);
}

void CBKKbdButn::FocusPressedkey(int nIdx)
{
	if (nIdx < m_nArraySize)
	{
		BKKey *pKey = m_pBKKeyboardArray + (DWORD_PTR)nIdx;
		HDC hdc = ::GetDC(GetSafeHwnd());
		HDC memDC = CreateCompatibleDC(hdc);
		HBITMAP memBM = CreateCompatibleBitmap(hdc, pKey->x2 - pKey->x1, pKey->y2 - pKey->y1);
		SelectObject(memDC, memBM);
		HGDIOBJ hOldBrush = SelectObject(memDC, m_brsh);
		HGDIOBJ hOldPen = SelectObject(memDC, m_pen);
		ExtFloodFill(memDC, 0, 0, RGB(0xff, 0xff, 0xff), FLOODFILLBORDER);
		BitBlt(hdc, pKey->x1, pKey->y1,
		       pKey->x2 - pKey->x1,
		       pKey->y2 - pKey->y1,
		       memDC, 0, 0, SRCAND);
		DeleteObject(memBM);
		DeleteDC(memDC);
	}
}

void CBKKbdButn::UnFocusPressedkey(int nIdx)
{
	if (nIdx < m_nArraySize)
	{
		BKKey *pKey = m_pBKKeyboardArray + (DWORD_PTR)nIdx;
		HDC hdc = ::GetDC(GetSafeHwnd());
		HDC memDC = CreateCompatibleDC(hdc);
		SelectObject(memDC, m_hBmp);
		BitBlt(hdc, pKey->x1, pKey->y1,
		       pKey->x2 - pKey->x1,
		       pKey->y2 - pKey->y1,
		       memDC, pKey->x1, pKey->y1, SRCCOPY);
		DeleteDC(memDC);
	}
}

int CBKKbdButn::GetKeyIndex(int x, int y)
{
	ASSERT(m_pBKKeyboardArray);
	int i = -1;

	while (m_pBKKeyboardArray[++i].nType != BKKEY_ENDARRAY)
	{
		if ((m_pBKKeyboardArray[i].x1 <= x) && (x <= m_pBKKeyboardArray[i].x2)
		        && (m_pBKKeyboardArray[i].y1 <= y) && (y <= m_pBKKeyboardArray[i].y2)
		   )
		{
			return i;
		}
	}

	return -1;
}

int CBKKbdButn::GetKeyIndexById(BKKeyType nType)
{
	ASSERT(m_pBKKeyboardArray);
	int i = -1;

	while (m_pBKKeyboardArray[++i].nType != BKKEY_ENDARRAY)
	{
		if (m_pBKKeyboardArray[i].nType == nType)
		{
			return i;
		}
	}

	return -1;
}

int CBKKbdButn::GetArraySize()
{
	ASSERT(m_pBKKeyboardArray);
	int i = -1;

	while (m_pBKKeyboardArray[++i].nType != BKKEY_ENDARRAY)
	{
		if (i == INT_MAX)
		{
			return -1;
		}
	}

	return i;
}

const BKKey CBKKbdButn::m_ButnKbdKeys[] =
{
	{ BKKEY_REGULAR,    5,      4,      71,     47,     0001,   0274 },      //ÏÎÂÒ
	{ BKKEY_REGULAR,    72,     4,      138,    47,     0003,   0060 },      //ÊÒ
	{ BKKEY_REGULAR,    139,    4,      205,    47,     0013,   0274 },      //del rgt
	{ BKKEY_REGULAR,    207,    4,      273,    47,     0026,   0060 },      //del
	{ BKKEY_REGULAR,    274,    4,      340,    47,     0027,   0060 },      //ins
	{ BKKEY_REGULAR,    341,    4,      407,    47,     0002,   0274 },      //ÈÍÄÑÓ
	{ BKKEY_REGULAR,    409,    4,      475,    47,     0004,   0274 },      //ÁËÎÊÐÅÄ
	{ BKKEY_REGULAR,    476,    4,      542,    47,     0000,   0274 },      //ØÀÃ
	{ BKKEY_REGULAR,    544,    4,      620,    47,     0014,   0060 },      //ÑÁÐ
	{ BKKEY_STOP   ,    621,    4,      699,    47,     0000,   0000 },      //ÑÒÎÏ
	{ BKKEY_LSHIFT ,    5,      49,     49,     92,     0000,   0000 },      //shift
	{ BKKEY_REGULAR,    50,     49,     93,     92,     0073,   0060 },      //;
	{ BKKEY_REGULAR,    95,     49,     138,    92,     0061,   0060 },      //1
	{ BKKEY_REGULAR,    140,    49,     183,    92,     0062,   0060 },      //2
	{ BKKEY_REGULAR,    185,    49,     228,    92,     0063,   0060 },      //3
	{ BKKEY_REGULAR,    230,    49,     273,    92,     0064,   0060 },      //4
	{ BKKEY_REGULAR,    275,    49,     318,    92,     0065,   0060 },      //5
	{ BKKEY_REGULAR,    320,    49,     363,    92,     0066,   0060 },      //6
	{ BKKEY_REGULAR,    365,    49,     408,    92,     0067,   0060 },      //7
	{ BKKEY_REGULAR,    410,    49,     453,    92,     0070,   0060 },      //8
	{ BKKEY_REGULAR,    454,    49,     497,    92,     0071,   0060 },      //9
	{ BKKEY_REGULAR,    499,    49,     542,    92,     0060,   0060 },      //0
	{ BKKEY_REGULAR,    544,    49,     587,    92,     0055,   0060 },      //-
	{ BKKEY_REGULAR,    589,    49,     632,    92,     0072,   0060 },      //:
	{ BKKEY_REGULAR,    634,    49,     699,    92,     0030,   0060 },      //backspace
	{ BKKEY_REGULAR,    5,      94,     70,     137,    0011,   0274 },      //ÒÀÁ
	{ BKKEY_REGULAR,    72,     94,     115,    137,    0112,   0060 },      //J
	{ BKKEY_REGULAR,    117,    94,     160,    137,    0103,   0060 },      //C
	{ BKKEY_REGULAR,    162,    94,     205,    137,    0125,   0060 },      //U
	{ BKKEY_REGULAR,    207,    94,     250,    137,    0113,   0060 },      //K
	{ BKKEY_REGULAR,    252,    94,     295,    137,    0105,   0060 },      //E
	{ BKKEY_REGULAR,    297,    94,     340,    137,    0116,   0060 },      //N
	{ BKKEY_REGULAR,    342,    94,     385,    137,    0107,   0060 },      //G
	{ BKKEY_REGULAR,    387,    94,     430,    137,    0133,   0060 },      //[
	{ BKKEY_REGULAR,    432,    94,     475,    137,    0135,   0060 },      //]
	{ BKKEY_REGULAR,    477,    94,     520,    137,    0132,   0060 },      //Z
	{ BKKEY_REGULAR,    521,    94,     564,    137,    0110,   0060 },      //H
	{ BKKEY_REGULAR,    566,    94,     609,    137,    0137,   0060 },      //Ú
	{ BKKEY_REGULAR,    611,    94,     654,    137,    0057,   0060 },      ///
	{ BKKEY_REGULAR,    656,    94,     699,    137,    0023,   0060 },      //ÂÑ
	{ BKKEY_CTRL   ,    5,      139,    81,     182,    0000,   0000 },      //ÑÓ
	{ BKKEY_REGULAR,    83,     139,    126,    182,    0106,   0060 },      //F
	{ BKKEY_REGULAR,    128,    139,    171,    182,    0131,   0060 },      //Y
	{ BKKEY_REGULAR,    173,    139,    216,    182,    0127,   0060 },      //W
	{ BKKEY_REGULAR,    218,    139,    261,    182,    0101,   0060 },      //A
	{ BKKEY_REGULAR,    262,    139,    305,    182,    0120,   0060 },      //P
	{ BKKEY_REGULAR,    307,    139,    350,    182,    0122,   0060 },      //R
	{ BKKEY_REGULAR,    352,    139,    395,    182,    0117,   0060 },      //O
	{ BKKEY_REGULAR,    397,    139,    440,    182,    0114,   0060 },      //L
	{ BKKEY_REGULAR,    442,    139,    485,    182,    0104,   0060 },      //D
	{ BKKEY_REGULAR,    487,    139,    530,    182,    0166,   0060 },      //V
	{ BKKEY_REGULAR,    532,    139,    575,    182,    0134,   0060 },      //Ý
	{ BKKEY_REGULAR,    577,    139,    620,    182,    0056,   0060 },      //.
	{ BKKEY_REGULAR,    622,    139,    699,    182,    0012,   0060 },      //enter
	{ BKKEY_ZAGL   ,    5,      184,    58,     227,    0000,   0000 },      //ÇÀÃË
	{ BKKEY_STR    ,    60,     184,    103,    227,    0000,   0000 },      //ÑÒÐ
	{ BKKEY_REGULAR,    105,    184,    148,    227,    0121,   0060 },      //Q
	{ BKKEY_REGULAR,    150,    184,    193,    227,    0136,   0060 },      //×
	{ BKKEY_REGULAR,    195,    184,    238,    227,    0123,   0060 },      //S
	{ BKKEY_REGULAR,    240,    184,    283,    227,    0115,   0060 },      //M
	{ BKKEY_REGULAR,    285,    184,    328,    227,    0111,   0060 },      //I
	{ BKKEY_REGULAR,    330,    184,    373,    227,    0124,   0060 },      //T
	{ BKKEY_REGULAR,    375,    184,    418,    227,    0130,   0060 },      //X
	{ BKKEY_REGULAR,    420,    184,    463,    227,    0102,   0060 },      //B
	{ BKKEY_REGULAR,    465,    184,    508,    227,    0100,   0060 },      //@
	{ BKKEY_REGULAR,    510,    184,    553,    227,    0054,   0060 },      //
	{ BKKEY_REGULAR,    5,      229,    93,     272,    0016,   0060 },      //ÐÓÑ
	{ BKKEY_ALT    ,    95,     229,    148,    272,    0000,   0000 },      //ÀÐ2
	{ BKKEY_REGULAR,    150,    229,    475,    272,    0040,   0060 },      //space
	{ BKKEY_REGULAR,    476,    229,    564,    272,    0017,   0060 },      //ËÀÒ
	{ BKKEY_REGULAR,    566,    206,    609,    249,    0010,   0060 },      //left
	{ BKKEY_REGULAR,    611,    184,    654,    227,    0032,   0060 },      //up
	{ BKKEY_REGULAR,    611,    229,    654,    272,    0033,   0060 },      //down
	{ BKKEY_REGULAR,    656,    206,    699,    249,    0031,   0060 },      //right
	{ BKKEY_ENDARRAY,   0,      0,      0,      0,      0,      0 }
};

const BKKey CBKKbdButn::m_PlenKbdKeys[] =
{
	{ BKKEY_ALT    ,    4,      3,      46,     45,     0000,   0000 },      //ÍÐ
	{ BKKEY_CTRL   ,    49,     3,      91,     45,     0000,   0000 },      //ÑÓ
	{ BKKEY_STOP   ,    94,     3,      136,    45,     0000,   0000 },      //ÑÒÎÏ
	{ BKKEY_REGULAR,    139,    3,      181,    45,     0000,   0274 },      //ØÀÃ
	{ BKKEY_REGULAR,    183,    3,      225,    45,     0002,   0274 },      //ÈÍÄÑÓ
	{ BKKEY_REGULAR,    228,    3,      270,    45,     0004,   0274 },      //ÁËÎÊÐÅÄ
	{ BKKEY_REGULAR,    273,    3,      315,    45,     0005,   0274 },      //ÃÐÀÔ
	{ BKKEY_REGULAR,    318,    3,      360,    45,     0006,   0274 },      //ÇÀÏ
	{ BKKEY_REGULAR,    363,    3,      405,    45,     0007,   0274 },      //ÑÒÈÐ
	{ BKKEY_REGULAR,    408,    3,      450,    45,     0015,   0060 },      //ÓÑÒÒÀÁ
	{ BKKEY_REGULAR,    453,    3,      495,    45,     0020,   0060 },      //ÑÁÐÒÀÁ
	{ BKKEY_RESERVED,   498,    3,      540,    45,     0003,   0060 },      //Ðåçåðâ
	{ BKKEY_REGULAR,    543,    3,      585,    45,     0023,   0060 },      //ÂÑ
	{ BKKEY_REGULAR,    587,    3,      629,    45,     0014,   0060 },      //ÑÁÐ
	{ BKKEY_REGULAR,    632,    3,      674,    45,     0024,   0060 },      //ÃÒ
	{ BKKEY_REGULAR,    677,    3,      719,    45,     0013,   0274 },      //ÑÁÐ ïð
	{ BKKEY_REGULAR,    4,      48,     46,     90,     0073,   0060 },      //";"
	{ BKKEY_REGULAR,    49,     48,     91,     90,     0061,   0060 },      //1
	{ BKKEY_REGULAR,    94,     48,     136,    90,     0062,   0060 },      //2
	{ BKKEY_REGULAR,    139,    48,     181,    90,     0063,   0060 },      //3
	{ BKKEY_REGULAR,    183,    48,     225,    90,     0064,   0060 },      //4
	{ BKKEY_REGULAR,    228,    48,     270,    90,     0065,   0060 },      //5
	{ BKKEY_REGULAR,    273,    48,     315,    90,     0066,   0060 },      //6
	{ BKKEY_REGULAR,    318,    48,     360,    90,     0067,   0060 },      //7
	{ BKKEY_REGULAR,    363,    48,     405,    90,     0070,   0060 },      //8
	{ BKKEY_REGULAR,    408,    48,     450,    90,     0071,   0060 },      //9
	{ BKKEY_REGULAR,    453,    48,     495,    90,     0060,   0060 },      //0
	{ BKKEY_REGULAR,    498,    48,     540,    90,     0055,   0060 },      //-
	{ BKKEY_REGULAR,    543,    48,     585,    90,     0034,   0060 },      //left-up
	{ BKKEY_REGULAR,    587,    48,     629,    90,     0032,   0060 },      //up
	{ BKKEY_REGULAR,    632,    48,     674,    90,     0035,   0060 },      //right-up
	{ BKKEY_REGULAR,    677,    48,     719,    90,     0001,   0274 },      //ÏÎÂÒ
	{ BKKEY_REGULAR,    4,      93,     46,     135,    0112,   0060 },      //J
	{ BKKEY_REGULAR,    49,     93,     91,     135,    0103,   0060 },      //C
	{ BKKEY_REGULAR,    94,     93,     136,    135,    0125,   0060 },      //U
	{ BKKEY_REGULAR,    139,    93,     181,    135,    0113,   0060 },      //K
	{ BKKEY_REGULAR,    183,    93,     225,    135,    0105,   0060 },      //E
	{ BKKEY_REGULAR,    228,    93,     270,    135,    0116,   0060 },      //N
	{ BKKEY_REGULAR,    273,    93,     315,    135,    0107,   0060 },      //G
	{ BKKEY_REGULAR,    318,    93,     360,    135,    0133,   0060 },      //[
	{ BKKEY_REGULAR,    363,    93,     405,    135,    0135,   0060 },      //]
	{ BKKEY_REGULAR,    408,    93,     450,    135,    0132,   0060 },      //Z
	{ BKKEY_REGULAR,    453,    93,     495,    135,    0110,   0060 },      //H
	{ BKKEY_REGULAR,    498,    93,     540,    135,    0072,   0060 },      //:
	{ BKKEY_REGULAR,    543,    93,     585,    135,    0010,   0060 },      //left
	{ BKKEY_REGULAR,    587,    93,     629,    135,    0022,   0060 },      //top
	{ BKKEY_REGULAR,    632,    93,     674,    135,    0031,   0060 },      //right
	{ BKKEY_RESERVED,   677,    93,     719,    135,    0000,   0000 },      //Ðåçåðâ
	{ BKKEY_REGULAR,    4,      138,    46,     180,    0106,   0060 },      //F
	{ BKKEY_REGULAR,    49,     138,    91,     180,    0131,   0060 },      //Y
	{ BKKEY_REGULAR,    94,     138,    136,    180,    0127,   0060 },      //W
	{ BKKEY_REGULAR,    139,    138,    181,    180,    0101,   0060 },      //A
	{ BKKEY_REGULAR,    183,    138,    225,    180,    0120,   0060 },      //P
	{ BKKEY_REGULAR,    228,    138,    270,    180,    0122,   0060 },      //R
	{ BKKEY_REGULAR,    273,    138,    315,    180,    0117,   0060 },      //O
	{ BKKEY_REGULAR,    318,    138,    360,    180,    0114,   0060 },      //L
	{ BKKEY_REGULAR,    363,    138,    405,    180,    0104,   0060 },      //D
	{ BKKEY_REGULAR,    408,    138,    450,    180,    0126,   0060 },      //V
	{ BKKEY_REGULAR,    453,    138,    495,    180,    0134,   0060 },      //Ý
	{ BKKEY_REGULAR,    498,    138,    540,    180,    0056,   0060 },      //.
	{ BKKEY_REGULAR,    543,    138,    585,    180,    0037,   0060 },      //left-down
	{ BKKEY_REGULAR,    587,    138,    629,    180,    0033,   0060 },      //down
	{ BKKEY_REGULAR,    632,    138,    674,    180,    0036,   0060 },      //right-down
	{ BKKEY_RESERVED,   677,    138,    719,    180,    0000,   0000 },      //Ðåçåðâ
	{ BKKEY_REGULAR,    4,      183,    46,     225,    0121,   0060 },      //Q
	{ BKKEY_REGULAR,    49,     183,    91,     225,    0136,   0060 },      //×
	{ BKKEY_REGULAR,    94,     183,    136,    225,    0123,   0060 },      //S
	{ BKKEY_REGULAR,    139,    183,    181,    225,    0115,   0060 },      //M
	{ BKKEY_REGULAR,    183,    183,    225,    225,    0111,   0060 },      //I
	{ BKKEY_REGULAR,    228,    183,    270,    225,    0124,   0060 },      //T
	{ BKKEY_REGULAR,    273,    183,    315,    225,    0130,   0060 },      //X
	{ BKKEY_REGULAR,    318,    183,    360,    225,    0102,   0060 },      //B
	{ BKKEY_REGULAR,    363,    183,    405,    225,    0100,   0060 },      //@
	{ BKKEY_REGULAR,    408,    183,    450,    225,    0054,   0060 },      //
	{ BKKEY_REGULAR,    453,    183,    495,    225,    0057,   0060 },      ///
	{ BKKEY_REGULAR,    498,    183,    540,    225,    0137,   0060 },      //ÇÁ
	{ BKKEY_REGULAR,    543,    183,    585,    225,    0026,   0060 },      //ñäâèæêà
	{ BKKEY_REGULAR,    587,    183,    629,    225,    0030,   0060 },      //backspace
	{ BKKEY_REGULAR,    632,    183,    674,    225,    0027,   0060 },      //ðàçäâèæêà
	{ BKKEY_RESERVED,   677,    183,    719,    225,    0000,   0000 },      //Ðåçåðâ
	{ BKKEY_LSHIFT ,    4,      228,    46,     270,    0000,   0000 },      //ÏÐ
	{ BKKEY_ZAGL   ,    49,     228,    91,     270,    0000,   0000 },      //ÇÀÃË
	{ BKKEY_REGULAR,    94,     228,    181,    270,    0016,   0060 },      //ÐÓÑ
	{ BKKEY_REGULAR,    183,    228,    360,    270,    0040,   0060 },      //space
	{ BKKEY_REGULAR,    363,    228,    450,    270,    0017,   0060 },      //ËÀÒ
	{ BKKEY_STR    ,    453,    228,    495,    270,    0000,   0000 },      //ÑÒÐ
	{ BKKEY_RSHIFT ,    498,    228,    540,    270,    0000,   0000 },      //ÏÐ-2
	{ BKKEY_REGULAR,    543,    228,    585,    270,    0011,   0274 },      //ÒÀÁ
	{ BKKEY_REGULAR,    587,    228,    674,    270,    0012,   0060 },      //ÂÂÎÄ
	{ BKKEY_RESERVED,   677,    228,    719,    270,    0000,   0000 },      //Ðåçåðâ
	{ BKKEY_ENDARRAY,   0,      0,      0,      0,      0,      0 }
};