Пример #1
0
Combobox::Combobox()
{
	options = { "Option 1", "Option 2", "Option 3", "Option 4", "Option 5" };
	setCursor(100, FALSE);
	paint();

	while (counter++ < 10000)
	{
		if (!ReadConsoleInput(handleIN, irInBuf, 128, &cNumRead))

			fdwMode = ENABLE_WINDOW_INPUT;

		// Dispatch the events to the appropriate handler. 

		for (i = 0; i < cNumRead; i++)
		{
			switch (irInBuf[i].EventType)
			{
			case KEY_EVENT: // keyboard input 
				KeyEventProc(irInBuf[i].Event.KeyEvent);
				break;

			case MOUSE_EVENT: // mouse input 
				MouseEventProc(irInBuf[i].Event.MouseEvent);
				break;

			default:
				break;
			}
		}
	}
	
}
Пример #2
0
void ComboBox::HandleInput(INPUT_RECORD iRecord) {
	//if (!isClicked) return;
	switch (iRecord.EventType)
	{
	case KEY_EVENT: // keyboard input 
		KeyEventProc(iRecord.Event.KeyEvent);
		break;

	case MOUSE_EVENT: // mouse input
		MouseEventProc(iRecord.Event.MouseEvent);
		break;

	default:
		//errorInput();
		break;
	}
}
Пример #3
0
static uintptr_t CPROC ConsoleInputThread( PTHREAD thread )
{
	PCONSOLE_INFO pdp = (PCONSOLE_INFO)GetThreadParam( thread );
   INPUT_RECORD irInBuf[128];
   //PTEXT pCommand;
   DWORD cNumRead, c;
   hInput = pdp->consolecon.hStdin;
      while( !gbExitThread )
      {
         if (! ReadConsoleInput(
                pdp->consolecon.hStdin,      // input buffer handle
                irInBuf,     // buffer to read into
                128,         // size of read buffer
                &cNumRead) ) // number of records read
         {
            MessageBox( NULL, "Bad things happened on console input...", "ERROR", MB_OK );
         }
         for( c = 0; c < cNumRead; c++ )
         {
            switch(irInBuf[c].EventType)
            {
                case KEY_EVENT: // keyboard input
                 //  KeyboardState[irInBuf[c].Event.KeyEvent.wVirtualKeyCode] =
                 //                      irInBuf[c].Event.KeyEvent.bKeyDown;
                   KeyEventProc(pdp, irInBuf[c].Event.KeyEvent);
                   break;
                   /*
                case WINDOW_BUFFER_SIZE_EVENT:
                   irInBuf[c].Event.WindowBufferSizeEvent.dwSize.Y = 50;
                   SetConsoleScreenBufferSize( consolecon.hStdout, irInBuf[c].Event.WindowBufferSizeEvent.dwSize );
                   DebugBreak();
                   break;
                   */
                default:
                   //DebugBreak();
                   break;
            }
         }
      }
   Close( pdp );
   ghInputThread = NULL;
	ExitThread( 0xE0F );
   return 0;
}
Пример #4
0
void TextBox::HandleInput(INPUT_RECORD iRecord) {
	//if (!isClicked) return;
	SetConsoleTextAttribute(handle, textDw);
	CONSOLE_CURSOR_INFO newCci = { 100, true };
	SetConsoleCursorInfo(handle, &newCci);
	if (!enableWrite) return;
	switch (iRecord.EventType)
	{
	case KEY_EVENT: // keyboard input 
		KeyEventProc(iRecord.Event.KeyEvent);
		break;

	case MOUSE_EVENT: // mouse input 
		MouseEventProc(iRecord.Event.MouseEvent);
		break;

	default:
		//errorInput();
		break;
	}
}
	void CSysEventMonitor::MonitorProc() {
		m_console = GetStdHandle(STD_INPUT_HANDLE);

		INPUT_RECORD ir[MAX_INPUT_REC_READ];
		DWORD recRead;

		while (!m_stop) {
			ASSERT(ReadConsoleInput(m_console, ir, MAX_INPUT_REC_READ, &recRead));
			for (DWORD i = 0; i < recRead; i++) {
				switch (ir[i].EventType) {
				case KEY_EVENT:
					KeyEventProc(ir[i].Event.KeyEvent);
					break;
				case MOUSE_EVENT:
					MouseEventProc(ir[i].Event.MouseEvent);
					break;
				case WINDOW_BUFFER_SIZE_EVENT:
					WinBufferSizeProc(ir[i].Event.WindowBufferSizeEvent);
					break;
				}
			}

		}
	}
int main(VOID)
{
	DWORD cNumRead, fdwMode, i;
	INPUT_RECORD irInBuf[128];
	int counter = 0;

	// Get the standard input handle. 

	hStdin = GetStdHandle(STD_INPUT_HANDLE);
	if (hStdin == INVALID_HANDLE_VALUE)
		ErrorExit("GetStdHandle");

	// Save the current input mode, to be restored on exit. 

	if (!GetConsoleMode(hStdin, &fdwSaveOldMode))
		ErrorExit("GetConsoleMode");

	// Enable the window and mouse input events. 

	fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
	if (!SetConsoleMode(hStdin, fdwMode))
		ErrorExit("SetConsoleMode");

	// Loop to read and handle the next 100 input events.
	COORD c = { 7, 7 };
	HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
	TextBox box(20,c,h,"");
	while (true)
	{
		// Wait for the events. 

		if (!ReadConsoleInput(
			hStdin,      // input buffer handle 
			irInBuf,     // buffer to read into 
			128,         // size of read buffer 
			&cNumRead)) // number of records read 
			ErrorExit("ReadConsoleInput");

		// Dispatch the events to the appropriate handler. 

		for (i = 0; i < cNumRead; i++)
		{
			switch (irInBuf[i].EventType)
			{
			case KEY_EVENT: // keyboard input 
				KeyEventProc(irInBuf[i].Event.KeyEvent,h,box);
				break;

			case MOUSE_EVENT: // mouse input 
				MouseEventProc(irInBuf[i].Event.MouseEvent,h,box);
				break;

			case WINDOW_BUFFER_SIZE_EVENT: // scrn buf. resizing 
				//ResizeEventProc(irInBuf[i].Event.WindowBufferSizeEvent);
				break;

			case FOCUS_EVENT:  // disregard focus events 

			case MENU_EVENT:   // disregard menu events 
				break;

			default:
				ErrorExit("Unknown event type");
				break;
			}
		}
	}

	// Restore input mode on exit.

	SetConsoleMode(hStdin, fdwSaveOldMode);

	return 0;
}
/* ************************************
* DWORD UseEvent(VOID) 
* 功能	使用事件进行控制台操作
**************************************/
DWORD UseEvent(VOID) 
{ 
	CHAR chBuffer[256]; 
	DWORD cRead;
	HANDLE hStdin; 
	DWORD cNumRead, fdwMode, fdwSaveOldMode, i; 
	INPUT_RECORD irInBuf[128]; 

	// 获取标准输入句柄
	hStdin = GetStdHandle(STD_INPUT_HANDLE); 
	if (hStdin == INVALID_HANDLE_VALUE) 
		MyErrorExit("GetStdHandle"); 

	// 保存当前的控制台模式
	if (! GetConsoleMode(hStdin, &fdwSaveOldMode) ) 
		MyErrorExit("GetConsoleMode"); 

	// 使能窗口鼠标输入事件
	fdwMode = ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT; 
	if (! SetConsoleMode(hStdin, fdwMode) ) 
		MyErrorExit("SetConsoleMode"); 

	// 循环读取输入
	while (1) 
	{ 

		// 等待事件
		if (! ReadConsoleInput( 
			hStdin,      // 输入句柄
			irInBuf,     // 保存输入的缓冲区 
			128,         // 缓冲区大小 
			&cNumRead) ) // 实际读取的大小 
			MyErrorExit("ReadConsoleInput"); 

		// 显示事件
		for (i = 0; i < cNumRead; i++) 
		{
			switch(irInBuf[i].EventType) 
			{ 
			case KEY_EVENT: // 键盘输入
				KeyEventProc(irInBuf[i].Event.KeyEvent); 
				break; 

			case MOUSE_EVENT: // 鼠标输入
				MouseEventProc(irInBuf[i].Event.MouseEvent); 
				break; 

			case WINDOW_BUFFER_SIZE_EVENT: // Resize
				ResizeEventProc( 
					irInBuf[i].Event.WindowBufferSizeEvent); 
				break; 

			case FOCUS_EVENT:  // focus 事件 

			case MENU_EVENT:   // menu 事件 
				break; 

			default: 
				MyErrorExit("unknown event type"); 
				break; 
			} 
		}
	} 
	return 0; 
}