|
|
1bab02 |
/*********************************************************/
|
|
|
1bab02 |
/* ptycon: a pty-console bridge */
|
|
|
1f983d |
/* Copyright (C) 2016--2017 Z. Gilboa */
|
|
|
1bab02 |
/* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */
|
|
|
1bab02 |
/*********************************************************/
|
|
|
1bab02 |
|
|
|
1bab02 |
#include <psxtypes/psxtypes.h>
|
|
|
1bab02 |
#include <ntcon/ntcon.h>
|
|
|
1bab02 |
#include <ntapi/ntapi.h>
|
|
|
1bab02 |
#include <gdi/gdi.h>
|
|
|
1bab02 |
|
|
|
1bab02 |
#include <ptycon/ptycon.h>
|
|
|
1bab02 |
#include "ptycon_driver_impl.h"
|
|
|
1bab02 |
|
|
|
0e0975 |
static int ptyc_dbg_input_record(void * hout, nt_input_record * rec)
|
|
|
0e0975 |
{
|
|
|
0e0975 |
char * ch;
|
|
|
0e0975 |
uintptr_t buffer[512/sizeof(uintptr_t)];
|
|
|
0e0975 |
uint32_t nwritten;
|
|
|
0e0975 |
|
|
|
0e0975 |
ntapi->tt_aligned_block_memset(
|
|
|
0e0975 |
buffer,0,sizeof(buffer));
|
|
|
0e0975 |
|
|
|
0e0975 |
ch = (char *)buffer;
|
|
|
0e0975 |
|
|
|
0e0975 |
switch (rec->event_type) {
|
|
|
0e0975 |
case NT_KEY_EVENT:
|
|
|
0e0975 |
ntapi->snprintf(ch,sizeof(buffer),
|
|
|
0e0975 |
"key event. "
|
|
|
0e0975 |
"key down: %d; "
|
|
|
0e0975 |
"repeat count: %d; "
|
|
|
0e0975 |
"virtual key code: 0x%04x; "
|
|
|
0e0975 |
"virtual scan code: 0x%04x; "
|
|
|
0e0975 |
"unicode char: 0x%04x; "
|
|
|
0e0975 |
"control key: 0x%04x.\n",
|
|
|
0e0975 |
rec->key_event.key_down,
|
|
|
0e0975 |
rec->key_event.repeat_count,
|
|
|
0e0975 |
rec->key_event.virtual_key_code,
|
|
|
0e0975 |
rec->key_event.virtual_scan_code,
|
|
|
0e0975 |
rec->key_event.unicode_char,
|
|
|
0e0975 |
rec->key_event.control_key_state);
|
|
|
0e0975 |
break;
|
|
|
0e0975 |
|
|
|
0e0975 |
case NT_MOUSE_EVENT:
|
|
|
0e0975 |
ntapi->snprintf(ch,sizeof(buffer),
|
|
|
0e0975 |
"mouse event. "
|
|
|
0e0975 |
"pos.x: %d; "
|
|
|
0e0975 |
"pos.y: %d; "
|
|
|
0e0975 |
"button state: 0x%04x; "
|
|
|
0e0975 |
"ctrl key state: 0x%04x; "
|
|
|
0e0975 |
"event flags: 0x%04x.\n",
|
|
|
0e0975 |
rec->mouse_event.mouse_position.x,
|
|
|
0e0975 |
rec->mouse_event.mouse_position.y,
|
|
|
0e0975 |
rec->mouse_event.button_state,
|
|
|
0e0975 |
rec->mouse_event.control_key_state,
|
|
|
0e0975 |
rec->mouse_event.event_flags);
|
|
|
0e0975 |
break;
|
|
|
0e0975 |
|
|
|
0e0975 |
case NT_WINDOW_BUFFER_SIZE_EVENT:
|
|
|
0e0975 |
ntapi->snprintf(ch,sizeof(buffer),
|
|
|
0e0975 |
"window event. "
|
|
|
0e0975 |
"size.x: %d; "
|
|
|
0e0975 |
"size.y: %d.\n",
|
|
|
0e0975 |
rec->window_event.size.x,
|
|
|
0e0975 |
rec->window_event.size.y);
|
|
|
0e0975 |
|
|
|
0e0975 |
break;
|
|
|
0e0975 |
|
|
|
0e0975 |
case NT_MENU_EVENT:
|
|
|
0e0975 |
ntapi->snprintf(ch,sizeof(buffer),
|
|
|
0e0975 |
"menu event. "
|
|
|
0e0975 |
"command id: %d.\n",
|
|
|
0e0975 |
rec->menu_event.command_id);
|
|
|
0e0975 |
break;
|
|
|
0e0975 |
|
|
|
0e0975 |
case NT_FOCUS_EVENT:
|
|
|
0e0975 |
ntapi->snprintf(ch,sizeof(buffer),
|
|
|
0e0975 |
"focus event. "
|
|
|
0e0975 |
"set focus: %d.\n",
|
|
|
0e0975 |
rec->focus_event.set_focus);
|
|
|
0e0975 |
break;
|
|
|
0e0975 |
|
|
|
0e0975 |
default:
|
|
|
0e0975 |
return NT_STATUS_INTERNAL_ERROR;
|
|
|
0e0975 |
}
|
|
|
0e0975 |
|
|
|
0e0975 |
return ntcon->write_console_ansi(
|
|
|
4fd16c |
hout,ch,
|
|
|
4fd16c |
(uint32_t)ntapi->tt_string_null_offset_multibyte(ch),
|
|
|
0e0975 |
&nwritten,0);
|
|
|
0e0975 |
}
|
|
|
0e0975 |
|
|
|
0e0975 |
|
|
|
5399d4 |
int __stdcall ptyc_dbg_event(struct ptyc_driver_ctx_impl * ictx)
|
|
|
1bab02 |
{
|
|
|
0e0975 |
nt_input_record conevt[64];
|
|
|
0e0975 |
uint32_t nread;
|
|
|
0e0975 |
unsigned i;
|
|
|
0e0975 |
|
|
|
0e0975 |
do {
|
|
|
0e0975 |
if (!(ntcon->read_console_input_utf16(
|
|
|
0e0975 |
ictx->tctx.hin,
|
|
|
0e0975 |
conevt,64,
|
|
|
0e0975 |
&nread)))
|
|
|
0e0975 |
return -1;
|
|
|
0e0975 |
|
|
|
0e0975 |
for (i=0; i
|
|
|
0e0975 |
if (!(ptyc_dbg_input_record(
|
|
|
0e0975 |
ictx->tctx.hout,
|
|
|
0e0975 |
&conevt[i])))
|
|
|
0e0975 |
return -2;
|
|
|
0e0975 |
} while (1);
|
|
|
0e0975 |
|
|
|
0e0975 |
return -3;
|
|
|
1bab02 |
}
|