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:
parent
107fdd8730
commit
339b2c7727
|
@ -86,17 +86,17 @@ typedef struct consoleEvent {
|
||||||
} consoleEvent;
|
} consoleEvent;
|
||||||
|
|
||||||
struct key_translation {
|
struct key_translation {
|
||||||
char incoming[5];
|
char incoming[6];
|
||||||
int vk;
|
int vk;
|
||||||
char outgoing[1];
|
char outgoing;
|
||||||
} key_translation;
|
} key_translation;
|
||||||
|
|
||||||
struct key_translation keys[] = {
|
struct key_translation keys[] = {
|
||||||
{ "\x1b", VK_ESCAPE, "\x1b" },
|
{ "\x1b", VK_ESCAPE, '\x1b' },
|
||||||
{ "\r", VK_RETURN, "\r" },
|
{ "\r", VK_RETURN, '\r' },
|
||||||
{ "\b", VK_BACK, "\b" },
|
{ "\b", VK_BACK, '\b' },
|
||||||
{ "\x7f", VK_BACK, "\b" },
|
{ "\x7f", VK_BACK, '\b' },
|
||||||
{ "\t", VK_TAB, "\t" },
|
{ "\t", VK_TAB, '\t' },
|
||||||
{ "\x1b[A", VK_UP, 0 },
|
{ "\x1b[A", VK_UP, 0 },
|
||||||
{ "\x1b[B", VK_DOWN, 0 },
|
{ "\x1b[B", VK_DOWN, 0 },
|
||||||
{ "\x1b[C", VK_RIGHT, 0 },
|
{ "\x1b[C", VK_RIGHT, 0 },
|
||||||
|
@ -212,8 +212,7 @@ SendKeyStroke(HANDLE hInput, int keyStroke, char character)
|
||||||
ir.Event.KeyEvent.wVirtualScanCode = 0;
|
ir.Event.KeyEvent.wVirtualScanCode = 0;
|
||||||
ir.Event.KeyEvent.dwControlKeyState = 0;
|
ir.Event.KeyEvent.dwControlKeyState = 0;
|
||||||
ir.Event.KeyEvent.uChar.UnicodeChar = 0;
|
ir.Event.KeyEvent.uChar.UnicodeChar = 0;
|
||||||
if (character != 0)
|
ir.Event.KeyEvent.uChar.AsciiChar = character;
|
||||||
ir.Event.KeyEvent.uChar.AsciiChar = character;
|
|
||||||
|
|
||||||
WriteConsoleInputA(hInput, &ir, 1, &wr);
|
WriteConsoleInputA(hInput, &ir, 1, &wr);
|
||||||
|
|
||||||
|
@ -224,21 +223,20 @@ SendKeyStroke(HANDLE hInput, int keyStroke, char character)
|
||||||
void
|
void
|
||||||
ProcessIncomingKeys(char * ansikey)
|
ProcessIncomingKeys(char * ansikey)
|
||||||
{
|
{
|
||||||
int nKey = 0;
|
int keylen = strlen(ansikey);
|
||||||
int index = ARRAYSIZE(keys);
|
|
||||||
|
|
||||||
while (nKey < index) {
|
if (!keylen)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int nKey=0; nKey < ARRAYSIZE(keys); nKey++) {
|
||||||
if (strcmp(ansikey, keys[nKey].incoming) == 0) {
|
if (strcmp(ansikey, keys[nKey].incoming) == 0) {
|
||||||
SendKeyStroke(child_in, keys[nKey].vk, keys[nKey].outgoing[0]);
|
SendKeyStroke(child_in, keys[nKey].vk, keys[nKey].outgoing);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
nKey++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nKey == index)
|
for (int i=0; i < keylen; i++)
|
||||||
for(int i=0; i < strlen(ansikey); i++)
|
SendKeyStroke(child_in, 0, ansikey[i]);
|
||||||
SendKeyStroke(child_in, 0, ansikey[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -852,30 +850,22 @@ ProcessPipes(LPVOID p)
|
||||||
|
|
||||||
/* process data from pipe_in and route appropriately */
|
/* process data from pipe_in and route appropriately */
|
||||||
while (1) {
|
while (1) {
|
||||||
ZeroMemory(buf, 128);
|
DWORD rd = 0;
|
||||||
DWORD rd = 0, wr = 0, i = -1;
|
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;
|
bStartup = FALSE;
|
||||||
while (++i < rd) {
|
for (DWORD i=0; i < rd; i++) {
|
||||||
INPUT_RECORD ir;
|
if (buf[i] == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
if (buf[i] == 3) { /*Ctrl+C - Raise Ctrl+C*/
|
if (buf[i] == 3) { /*Ctrl+C - Raise Ctrl+C*/
|
||||||
GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
|
GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bAnsi) {
|
if (bAnsi) {
|
||||||
ir.EventType = KEY_EVENT;
|
SendKeyStroke(child_in, 0, buf[i]);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
ProcessIncomingKeys(buf);
|
ProcessIncomingKeys(buf);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue