#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, 4, 3, 51, 34, 0001, 0274 },      //ÏÎÂÒ
	{ BKKEY_REGULAR, 52, 3, 101, 34, 0003, 0060 },      //ÊÒ
	{ BKKEY_REGULAR, 102, 3, 149, 34, 0013, 0274 },      //del rgt
	{ BKKEY_REGULAR, 150, 3, 198, 34, 0026, 0060 },      //del
	{ BKKEY_REGULAR, 199, 3, 248, 34, 0027, 0060 },      //ins
	{ BKKEY_REGULAR, 249, 3, 297, 34, 0002, 0274 },      //ÈÍÄÑÓ
	{ BKKEY_REGULAR, 298, 3, 346, 34, 0004, 0274 },      //ÁËÎÊÐÅÄ
	{ BKKEY_REGULAR, 347, 3, 395, 34, 0000, 0274 },      //ØÀÃ
	{ BKKEY_REGULAR, 396, 3, 451, 34, 0014, 0060 },      //ÑÁÐ
	{ BKKEY_STOP, 452, 3, 509, 34, 0000, 0000 },      //ÑÒÎÏ
	{ BKKEY_LSHIFT, 4, 35, 35, 67, 0000, 0000 },      //shift
	{ BKKEY_REGULAR, 36, 35, 68, 67, 0073, 0060 },      //;
	{ BKKEY_REGULAR, 69, 35, 100, 67, 0061, 0060 },      //1
	{ BKKEY_REGULAR, 101, 35, 133, 67, 0062, 0060 },      //2
	{ BKKEY_REGULAR, 134, 35, 166, 67, 0063, 0060 },      //3
	{ BKKEY_REGULAR, 167, 35, 198, 67, 0064, 0060 },      //4
	{ BKKEY_REGULAR, 199, 35, 231, 67, 0065, 0060 },      //5
	{ BKKEY_REGULAR, 232, 35, 264, 67, 0066, 0060 },      //6
	{ BKKEY_REGULAR, 265, 35, 296, 67, 0067, 0060 },      //7
	{ BKKEY_REGULAR, 297, 35, 329, 67, 0070, 0060 },      //8
	{ BKKEY_REGULAR, 330, 35, 362, 67, 0071, 0060 },      //9
	{ BKKEY_REGULAR, 363, 35, 394, 67, 0060, 0060 },      //0
	{ BKKEY_REGULAR, 395, 35, 427, 67, 0055, 0060 },      //-
	{ BKKEY_REGULAR, 428, 35, 460, 67, 0072, 0060 },      //:
	{ BKKEY_REGULAR, 461, 35, 508, 67, 0030, 0060 },      //backspace
	{ BKKEY_REGULAR, 4, 68, 51, 100, 0011, 0274 },      //ÒÀÁ
	{ BKKEY_REGULAR, 52, 68, 84, 100, 0112, 0060 },      //J
	{ BKKEY_REGULAR, 85, 68, 117, 100, 0103, 0060 },      //C
	{ BKKEY_REGULAR, 118, 68, 149, 100, 0125, 0060 },      //U
	{ BKKEY_REGULAR, 150, 68, 182, 100, 0113, 0060 },      //K
	{ BKKEY_REGULAR, 183, 68, 215, 100, 0105, 0060 },      //E
	{ BKKEY_REGULAR, 216, 68, 247, 100, 0116, 0060 },      //N
	{ BKKEY_REGULAR, 248, 68, 280, 100, 0107, 0060 },      //G
	{ BKKEY_REGULAR, 281, 68, 313, 100, 0133, 0060 },      //[
	{ BKKEY_REGULAR, 314, 68, 345, 100, 0135, 0060 },      //]
	{ BKKEY_REGULAR, 346, 68, 378, 100, 0132, 0060 },      //Z
	{ BKKEY_REGULAR, 379, 68, 411, 100, 0110, 0060 },      //H
	{ BKKEY_REGULAR, 412, 68, 443, 100, 0137, 0060 },      //Ú
	{ BKKEY_REGULAR, 444, 68, 476, 100, 0057, 0060 },      ///
	{ BKKEY_REGULAR, 477, 68, 508, 100, 0023, 0060 },      //ÂÑ
	{ BKKEY_CTRL, 4, 101, 58, 132, 0000, 0000 },      //ÑÓ
	{ BKKEY_REGULAR, 60, 101, 92, 132, 0106, 0060 },      //F
	{ BKKEY_REGULAR, 93, 101, 124, 132, 0131, 0060 },      //Y
	{ BKKEY_REGULAR, 125, 101, 157, 132, 0127, 0060 },      //W
	{ BKKEY_REGULAR, 158, 101, 190, 132, 0101, 0060 },      //A
	{ BKKEY_REGULAR, 191, 101, 222, 132, 0120, 0060 },      //P
	{ BKKEY_REGULAR, 223, 101, 255, 132, 0122, 0060 },      //R
	{ BKKEY_REGULAR, 256, 101, 288, 132, 0117, 0060 },      //O
	{ BKKEY_REGULAR, 289, 101, 320, 133, 0114, 0060 },      //L
	{ BKKEY_REGULAR, 321, 101, 353, 132, 0104, 0060 },      //D
	{ BKKEY_REGULAR, 354, 101, 386, 132, 0166, 0060 },      //V
	{ BKKEY_REGULAR, 387, 101, 418, 132, 0134, 0060 },      //Ý
	{ BKKEY_REGULAR, 419, 101, 451, 132, 0056, 0060 },      //.
	{ BKKEY_REGULAR, 452, 101, 508, 132, 0012, 0060 },      //enter
	{ BKKEY_ZAGL, 4, 133, 43, 165, 0000, 0000 },      //ÇÀÃË
	{ BKKEY_STR, 44, 133, 75, 165, 0000, 0000 },      //ÑÒÐ
	{ BKKEY_REGULAR, 76, 133, 108, 165, 0121, 0060 },      //Q
	{ BKKEY_REGULAR, 109, 133, 141, 165, 0136, 0060 },      //×
	{ BKKEY_REGULAR, 142, 133, 174, 165, 0123, 0060 },      //S
	{ BKKEY_REGULAR, 175, 133, 206, 165, 0115, 0060 },      //M
	{ BKKEY_REGULAR, 207, 133, 239, 165, 0111, 0060 },      //I
	{ BKKEY_REGULAR, 240, 133, 271, 165, 0124, 0060 },      //T
	{ BKKEY_REGULAR, 272, 133, 304, 165, 0130, 0060 },      //X
	{ BKKEY_REGULAR, 305, 133, 337, 165, 0102, 0060 },      //B
	{ BKKEY_REGULAR, 338, 133, 369, 165, 0100, 0060 },      //@
	{ BKKEY_REGULAR, 370, 133, 411, 165, 0054, 0060 },      //
	{ BKKEY_REGULAR, 4, 166, 67, 197, 0016, 0060 },      //ÐÓÑ
	{ BKKEY_ALT, 68, 166, 108, 197, 0000, 0000 },      //ÀÐ2
	{ BKKEY_REGULAR, 109, 166, 346, 197, 0040, 0060 },      //space
	{ BKKEY_REGULAR, 347, 166, 411, 197, 0017, 0060 },      //ËÀÒ
	{ BKKEY_REGULAR, 412, 150, 443, 180, 0010, 0060 },      //left
	{ BKKEY_REGULAR, 444, 133, 476, 165, 0032, 0060 },      //up
	{ BKKEY_REGULAR, 444, 166, 476, 197, 0033, 0060 },      //down
	{ BKKEY_REGULAR, 477, 150, 508, 180, 0031, 0060 },      //right
	{ BKKEY_ENDARRAY,   0,      0,      0,      0,      0,      0 }
};

const BKKey CBKKbdButn::m_PlenKbdKeys[] =
{
	{ BKKEY_ALT, 2, 3, 33, 34, 0000, 0000 },      //ÍÐ
	{ BKKEY_CTRL, 34, 3, 65, 34, 0000, 0000 },      //ÑÓ
	{ BKKEY_STOP, 66, 3, 96, 34, 0000, 0000 },      //ÑÒÎÏ
	{ BKKEY_REGULAR, 97, 3, 128, 34, 0000, 0274 },      //ØÀÃ
	{ BKKEY_REGULAR, 129, 3, 160, 34, 0002, 0274 },      //ÈÍÄÑÓ
	{ BKKEY_REGULAR, 161, 3, 192, 34, 0004, 0274 },      //ÁËÎÊÐÅÄ
	{ BKKEY_REGULAR, 193, 3, 224, 34, 0005, 0274 },      //ÃÐÀÔ
	{ BKKEY_REGULAR, 225, 3, 256, 34, 0006, 0274 },      //ÇÀÏ
	{ BKKEY_REGULAR, 257, 3, 287, 34, 0007, 0274 },      //ÑÒÈÐ
	{ BKKEY_REGULAR, 288, 3, 319, 34, 0015, 0060 },      //ÓÑÒÒÀÁ
	{ BKKEY_REGULAR, 320, 3, 351, 34, 0020, 0060 },      //ÑÁÐÒÀÁ
	{ BKKEY_RESERVED, 352, 3, 383, 34, 0003, 0060 },      //Ðåçåðâ
	{ BKKEY_REGULAR, 384, 3, 415, 34, 0023, 0060 },      //ÂÑ
	{ BKKEY_REGULAR, 416, 3, 447, 34, 0014, 0060 },      //ÑÁÐ
	{ BKKEY_REGULAR, 448, 3, 478, 34, 0024, 0060 },      //ÃÒ
	{ BKKEY_REGULAR, 479, 3, 510, 34, 0013, 0274 },      //ÑÁÐ ïð
	{ BKKEY_REGULAR, 2, 35, 33, 67, 0073, 0060 },      //";"
	{ BKKEY_REGULAR, 34, 35, 65, 67, 0061, 0060 },      //1
	{ BKKEY_REGULAR, 66, 35, 96, 67, 0062, 0060 },      //2
	{ BKKEY_REGULAR, 97, 35, 128, 67, 0063, 0060 },      //3
	{ BKKEY_REGULAR, 129, 35, 160, 67, 0064, 0060 },      //4
	{ BKKEY_REGULAR, 161, 35, 192, 67, 0065, 0060 },      //5
	{ BKKEY_REGULAR, 193, 35, 224, 67, 0066, 0060 },      //6
	{ BKKEY_REGULAR, 225, 35, 256, 67, 0067, 0060 },      //7
	{ BKKEY_REGULAR, 257, 35, 287, 67, 0070, 0060 },      //8
	{ BKKEY_REGULAR, 288, 35, 319, 67, 0071, 0060 },      //9
	{ BKKEY_REGULAR, 320, 35, 351, 67, 0060, 0060 },      //0
	{ BKKEY_REGULAR, 352, 35, 383, 67, 0055, 0060 },      //-
	{ BKKEY_REGULAR, 384, 35, 415, 67, 0034, 0060 },      //left-up
	{ BKKEY_REGULAR, 416, 35, 447, 67, 0032, 0060 },      //up
	{ BKKEY_REGULAR, 448, 35, 478, 67, 0035, 0060 },      //right-up
	{ BKKEY_REGULAR, 479, 35, 510, 67, 0001, 0274 },      //ÏÎÂÒ
	{ BKKEY_REGULAR, 2, 68, 33, 99, 0112, 0060 },      //J
	{ BKKEY_REGULAR, 34, 68, 65, 99, 0103, 0060 },      //C
	{ BKKEY_REGULAR, 66, 68, 96, 99, 0125, 0060 },      //U
	{ BKKEY_REGULAR, 97, 68, 128, 99, 0113, 0060 },      //K
	{ BKKEY_REGULAR, 129, 68, 160, 99, 0105, 0060 },      //E
	{ BKKEY_REGULAR, 161, 68, 192, 99, 0116, 0060 },      //N
	{ BKKEY_REGULAR, 193, 68, 224, 99, 0107, 0060 },      //G
	{ BKKEY_REGULAR, 225, 68, 256, 99, 0133, 0060 },      //[
	{ BKKEY_REGULAR, 257, 68, 287, 99, 0135, 0060 },      //]
	{ BKKEY_REGULAR, 288, 68, 319, 99, 0132, 0060 },      //Z
	{ BKKEY_REGULAR, 320, 68, 351, 99, 0110, 0060 },      //H
	{ BKKEY_REGULAR, 352, 68, 383, 99, 0072, 0060 },      //:
	{ BKKEY_REGULAR, 384, 68, 415, 99, 0010, 0060 },      //left
	{ BKKEY_REGULAR, 416, 68, 447, 99, 0022, 0060 },      //top
	{ BKKEY_REGULAR, 448, 68, 478, 99, 0031, 0060 },      //right
	{ BKKEY_RESERVED, 479, 68, 510, 99, 0000, 0000 },      //Ðåçåðâ
	{ BKKEY_REGULAR, 2, 101, 33, 132, 0106, 0060 },      //F
	{ BKKEY_REGULAR, 34, 101, 65, 132, 0131, 0060 },      //Y
	{ BKKEY_REGULAR, 66, 101, 96, 132, 0127, 0060 },      //W
	{ BKKEY_REGULAR, 97, 101, 128, 132, 0101, 0060 },      //A
	{ BKKEY_REGULAR, 129, 101, 160, 132, 0120, 0060 },      //P
	{ BKKEY_REGULAR, 161, 101, 192, 132, 0122, 0060 },      //R
	{ BKKEY_REGULAR, 193, 101, 224, 132, 0117, 0060 },      //O
	{ BKKEY_REGULAR, 225, 101, 256, 132, 0114, 0060 },      //L
	{ BKKEY_REGULAR, 257, 101, 287, 132, 0104, 0060 },      //D
	{ BKKEY_REGULAR, 288, 101, 319, 132, 0126, 0060 },      //V
	{ BKKEY_REGULAR, 320, 101, 351, 132, 0134, 0060 },      //Ý
	{ BKKEY_REGULAR, 352, 101, 383, 132, 0056, 0060 },      //.
	{ BKKEY_REGULAR, 384, 101, 415, 132, 0037, 0060 },      //left-down
	{ BKKEY_REGULAR, 416, 101, 447, 132, 0033, 0060 },      //down
	{ BKKEY_REGULAR, 448, 101, 478, 132, 0036, 0060 },      //right-down
	{ BKKEY_RESERVED, 479, 101, 510, 132, 0000, 0000 },      //Ðåçåðâ
	{ BKKEY_REGULAR, 2, 133, 33, 165, 0121, 0060 },      //Q
	{ BKKEY_REGULAR, 34, 133, 65, 165, 0136, 0060 },      //×
	{ BKKEY_REGULAR, 66, 133, 96, 165, 0123, 0060 },      //S
	{ BKKEY_REGULAR, 97, 133, 128, 165, 0115, 0060 },      //M
	{ BKKEY_REGULAR, 129, 133, 160, 165, 0111, 0060 },      //I
	{ BKKEY_REGULAR, 161, 133, 192, 165, 0124, 0060 },      //T
	{ BKKEY_REGULAR, 193, 133, 224, 165, 0130, 0060 },      //X
	{ BKKEY_REGULAR, 225, 133, 256, 165, 0102, 0060 },      //B
	{ BKKEY_REGULAR, 257, 133, 287, 165, 0100, 0060 },      //@
	{ BKKEY_REGULAR, 288, 133, 319, 165, 0054, 0060 },      //
	{ BKKEY_REGULAR, 320, 133, 351, 165, 0057, 0060 },      ///
	{ BKKEY_REGULAR, 352, 133, 383, 165, 0137, 0060 },      //ÇÁ
	{ BKKEY_REGULAR, 384, 133, 415, 165, 0026, 0060 },      //ñäâèæêà
	{ BKKEY_REGULAR, 416, 133, 447, 165, 0030, 0060 },      //backspace
	{ BKKEY_REGULAR, 448, 133, 478, 165, 0027, 0060 },      //ðàçäâèæêà
	{ BKKEY_RESERVED, 479, 133, 510, 165, 0000, 0000 },      //Ðåçåðâ
	{ BKKEY_LSHIFT, 2, 166, 33, 197, 0000, 0000 },      //ÏÐ
	{ BKKEY_ZAGL, 34, 166, 65, 197, 0000, 0000 },      //ÇÀÃË
	{ BKKEY_REGULAR, 66, 166, 128, 197, 0016, 0060 },      //ÐÓÑ
	{ BKKEY_REGULAR, 129, 166, 256, 197, 0040, 0060 },      //space
	{ BKKEY_REGULAR, 257, 166, 319, 197, 0017, 0060 },      //ËÀÒ
	{ BKKEY_STR, 320, 166, 351, 197, 0000, 0000 },      //ÑÒÐ
	{ BKKEY_RSHIFT, 352, 166, 383, 197, 0000, 0000 },      //ÏÐ-2
	{ BKKEY_REGULAR, 384, 166, 415, 197, 0011, 0274 },      //ÒÀÁ
	{ BKKEY_REGULAR, 416, 166, 478, 197, 0012, 0060 },      //ÂÂÎÄ
	{ BKKEY_RESERVED, 479, 166, 510, 197, 0000, 0000 },      //Ðåçåðâ
	{ BKKEY_ENDARRAY,   0,      0,      0,      0,      0,      0 }
};
