Hallo, ich habe vor eine Shell zu bauen, welche auf die TAB Taste reagiert und dann jeweils im aktuellen Verzeichnis alle Dateien/Verzeichnisse auflistet so wie bei cmd.exe
Habe schon bißchen vorgearbeitet:
Der Code reagiert auf die TAB Taste, doch wie bekomme ich eine Normale Eingabe mit ReadConsoleInput() hin? Mit der ReadConsole() Funktion ist es einfacher aber da kann man keine Tastatur KeyEvents abfangen
Wie bekommt man das Grundgerüst wie bei cmd.exe hin???
Bitte um Hilfe!!!
Habe schon bißchen vorgearbeitet:
Code:
#include <windows.h> #include <stdio.h> #include <iostream> #include <string> using namespace std; //Eingabe String string input = ""; VOID ErrorExit (LPSTR lpszMessage) { fprintf(stderr, "%s\n", lpszMessage); ExitProcess(0); } //VOID KeyEventProc(KEY_EVENT_RECORD ker, HANDLE hStdin, DWORD fdwSaveOldMode) VOID KeyEventProc(KEY_EVENT_RECORD ker) { //Wartet auf TAB Taste if(ker.wVirtualKeyCode == VK_TAB) { if(ker.bKeyDown) cout << "#TAB EVENT PRESSED#"; else cout << "#TAB EVENT RELEASED#"; } //Wartet auf Enter Taste else if(ker.wVirtualKeyCode == VK_RETURN) { cout << "NEWLINE" << endl; cout << input << endl; //Input löschen input.clear(); } if(ker.wVirtualKeyCode == VK_BACK) { cout << "löschen" << endl; } //Normale String Eingabe else { //Alte Einstellungen wiederherstellen //SetConsoleMode(hStdin, fdwSaveOldMode); if(ker.bKeyDown){} else { cout << "Zeichen: " << ker.uChar.AsciiChar << endl; input += ker.uChar.AsciiChar; } } } int ReadKeyInput() { HANDLE hStdin; DWORD cNumRead, fdwMode, fdwSaveOldMode, i; INPUT_RECORD irInBuf[128]; int counter=0; // Get the standard input handle. hStdin = GetStdHandle(STD_INPUT_HANDLE); if (hStdin == INVALID_HANDLE_VALUE) ErrorExit(TEXT("GetStdHandle")); // Save the current input mode, to be restored on exit. if (! GetConsoleMode(hStdin, &fdwSaveOldMode) ) ErrorExit(TEXT("GetConsoleMode")); // Enable the window and mouse input events. fdwMode = ENABLE_WINDOW_INPUT; if (! SetConsoleMode(hStdin, fdwMode) ) ErrorExit(TEXT("SetConsoleMode")); // Loop to read and handle the input events. while (counter++ <= 100) //while(1) { // Wait for the events. //if(!ReadConsole(hStdin, irInBuf, 128, &cNumRead, NULL)) // ErrorExit(TEXT("ReadConsole")); if (! ReadConsoleInput( hStdin, // input buffer handle irInBuf, // buffer to read into 128, // size of read buffer &cNumRead) ) // number of records read ErrorExit(TEXT("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, hStdin, fdwSaveOldMode); KeyEventProc(irInBuf[i].Event.KeyEvent); break; } } } return 0; } int main(VOID) { ReadKeyInput(); return 0; }
Der Code reagiert auf die TAB Taste, doch wie bekomme ich eine Normale Eingabe mit ReadConsoleInput() hin? Mit der ReadConsole() Funktion ist es einfacher aber da kann man keine Tastatur KeyEvents abfangen
Wie bekommt man das Grundgerüst wie bei cmd.exe hin???
Bitte um Hilfe!!!
Comment