shell: Cleanup shellhost (use func SendKeyStroke) (#116)

* shell: Cleanup shellhost (use func SendKeyStroke)

* shell: Fix console key mapping

Fix IntelliSense error:
a value of type "const char [6]" cannot be used to initialize an entity of type "char [5]"
This commit is contained in:
Oleg S 2017-04-28 07:04:14 +03:00 committed by Manoj Ampalam
parent 107fdd8730
commit 339b2c7727
1 changed files with 25 additions and 35 deletions

View File

@ -86,17 +86,17 @@ typedef struct consoleEvent {
} consoleEvent;
struct key_translation {
char incoming[5];
char incoming[6];
int vk;
char outgoing[1];
char outgoing;
} key_translation;
struct key_translation keys[] = {
{ "\x1b", VK_ESCAPE, "\x1b" },
{ "\r", VK_RETURN, "\r" },
{ "\b", VK_BACK, "\b" },
{ "\x7f", VK_BACK, "\b" },
{ "\t", VK_TAB, "\t" },
{ "\x1b", VK_ESCAPE, '\x1b' },
{ "\r", VK_RETURN, '\r' },
{ "\b", VK_BACK, '\b' },
{ "\x7f", VK_BACK, '\b' },
{ "\t", VK_TAB, '\t' },
{ "\x1b[A", VK_UP, 0 },
{ "\x1b[B", VK_DOWN, 0 },
{ "\x1b[C", VK_RIGHT, 0 },
@ -212,7 +212,6 @@ SendKeyStroke(HANDLE hInput, int keyStroke, char character)
ir.Event.KeyEvent.wVirtualScanCode = 0;
ir.Event.KeyEvent.dwControlKeyState = 0;
ir.Event.KeyEvent.uChar.UnicodeChar = 0;
if (character != 0)
ir.Event.KeyEvent.uChar.AsciiChar = character;
WriteConsoleInputA(hInput, &ir, 1, &wr);
@ -224,20 +223,19 @@ SendKeyStroke(HANDLE hInput, int keyStroke, char character)
void
ProcessIncomingKeys(char * ansikey)
{
int nKey = 0;
int index = ARRAYSIZE(keys);
int keylen = strlen(ansikey);
while (nKey < index) {
if (!keylen)
return;
for (int nKey=0; nKey < ARRAYSIZE(keys); nKey++) {
if (strcmp(ansikey, keys[nKey].incoming) == 0) {
SendKeyStroke(child_in, keys[nKey].vk, keys[nKey].outgoing[0]);
break;
SendKeyStroke(child_in, keys[nKey].vk, keys[nKey].outgoing);
return;
}
else
nKey++;
}
if (nKey == index)
for(int i=0; i < strlen(ansikey); i++)
for (int i=0; i < keylen; i++)
SendKeyStroke(child_in, 0, ansikey[i]);
}
@ -852,30 +850,22 @@ ProcessPipes(LPVOID p)
/* process data from pipe_in and route appropriately */
while (1) {
ZeroMemory(buf, 128);
DWORD rd = 0, wr = 0, i = -1;
DWORD rd = 0;
ZeroMemory(buf, sizeof(buf));
GOTO_CLEANUP_ON_FALSE(ReadFile(pipe_in, buf, 127, &rd, NULL)); /* read bufsize-1 */
GOTO_CLEANUP_ON_FALSE(ReadFile(pipe_in, buf, sizeof(buf)-1, &rd, NULL)); /* read bufsize-1 */
bStartup = FALSE;
while (++i < rd) {
INPUT_RECORD ir;
for (DWORD i=0; i < rd; i++) {
if (buf[i] == 0)
break;
if (buf[i] == 3) { /*Ctrl+C - Raise Ctrl+C*/
GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
continue;
}
if (bAnsi) {
ir.EventType = KEY_EVENT;
ir.Event.KeyEvent.bKeyDown = TRUE;
ir.Event.KeyEvent.wRepeatCount = 1;
ir.Event.KeyEvent.wVirtualKeyCode = 0;
ir.Event.KeyEvent.wVirtualScanCode = 0;
ir.Event.KeyEvent.uChar.AsciiChar = buf[i];
ir.Event.KeyEvent.dwControlKeyState = 0;
WriteConsoleInputA(child_in, &ir, 1, &wr);
ir.Event.KeyEvent.bKeyDown = FALSE;
WriteConsoleInputA(child_in, &ir, 1, &wr);
SendKeyStroke(child_in, 0, buf[i]);
} else {
ProcessIncomingKeys(buf);
break;