2009-03-01 13:13:25 +00:00
|
|
|
/* Windows TermIO
|
|
|
|
*
|
|
|
|
* copyright (C) 2003 Sascha Sommer
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2003-03-30 21:20:04 +00:00
|
|
|
|
|
|
|
// See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
|
|
|
|
// for additional virtual keycodes
|
|
|
|
|
|
|
|
|
2007-03-04 19:04:08 +00:00
|
|
|
#include "config.h"
|
2007-03-04 18:55:44 +00:00
|
|
|
#include <stdio.h>
|
2010-02-28 00:24:01 +00:00
|
|
|
#include <stdint.h>
|
2009-05-31 13:00:51 +00:00
|
|
|
#include <string.h>
|
2003-03-30 21:20:04 +00:00
|
|
|
#include <windows.h>
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/keycodes.h"
|
|
|
|
#include "input/input.h"
|
2013-12-19 20:31:27 +00:00
|
|
|
#include "terminal.h"
|
2008-04-29 11:52:45 +00:00
|
|
|
|
2013-07-14 14:08:27 +00:00
|
|
|
int mp_input_slave_cmd_func(int fd, char *dest, int size)
|
|
|
|
{
|
|
|
|
DWORD retval;
|
|
|
|
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
if (PeekNamedPipe(in, NULL, size, &retval, NULL, NULL)) {
|
|
|
|
if (size > retval)
|
|
|
|
size = retval;
|
|
|
|
} else {
|
|
|
|
if (WaitForSingleObject(in, 0))
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
if (!size)
|
|
|
|
return MP_INPUT_NOTHING;
|
|
|
|
ReadFile(in, dest, size, &retval, NULL);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
return MP_INPUT_NOTHING;
|
2003-09-22 11:31:51 +00:00
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
|
2013-07-14 14:08:27 +00:00
|
|
|
int screen_width = 80;
|
|
|
|
int screen_height = 24;
|
|
|
|
char *erase_to_end_of_line = NULL;
|
2003-03-30 21:20:04 +00:00
|
|
|
|
2013-07-14 14:08:27 +00:00
|
|
|
void get_screen_size(void)
|
|
|
|
{
|
2011-10-22 14:24:16 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO cinfo;
|
2013-07-14 14:08:27 +00:00
|
|
|
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cinfo)) {
|
2011-10-22 14:24:16 +00:00
|
|
|
screen_width = cinfo.dwMaximumWindowSize.X;
|
|
|
|
screen_height = cinfo.dwMaximumWindowSize.Y;
|
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
2013-07-25 15:23:40 +00:00
|
|
|
int load_termcap(char *termtype)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-27 21:50:59 +00:00
|
|
|
static HANDLE in;
|
2013-07-14 14:08:27 +00:00
|
|
|
static int getch2_status = 0;
|
2003-03-30 21:20:04 +00:00
|
|
|
|
2007-08-25 04:28:08 +00:00
|
|
|
static int getch2_internal(void)
|
|
|
|
{
|
2013-07-14 14:08:27 +00:00
|
|
|
INPUT_RECORD eventbuffer[128];
|
2003-03-30 21:20:04 +00:00
|
|
|
DWORD retval;
|
2013-07-14 14:08:27 +00:00
|
|
|
int i = 0;
|
|
|
|
if (!getch2_status) {
|
|
|
|
// supports e.g. MinGW xterm, unfortunately keys are only received after
|
|
|
|
// enter was pressed.
|
|
|
|
uint8_t c;
|
|
|
|
if (!PeekNamedPipe(in, NULL, 1, &retval, NULL, NULL) || !retval)
|
|
|
|
return -1;
|
|
|
|
ReadFile(in, &c, 1, &retval, NULL);
|
|
|
|
return retval == 1 ? c : -1;
|
2010-02-28 00:24:01 +00:00
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
/*check if there are input events*/
|
2013-07-14 14:08:27 +00:00
|
|
|
if (!GetNumberOfConsoleInputEvents(in, &retval)) {
|
|
|
|
printf("getch2: can't get number of input events: %i\n",
|
|
|
|
(int)GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (retval <= 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*read all events*/
|
|
|
|
if (!ReadConsoleInput(in, eventbuffer, 128, &retval)) {
|
|
|
|
printf("getch: can't read input events\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*filter out keyevents*/
|
|
|
|
for (i = 0; i < retval; i++) {
|
|
|
|
switch (eventbuffer[i].EventType) {
|
|
|
|
case KEY_EVENT:
|
|
|
|
/*only a pressed key is interresting for us*/
|
|
|
|
if (eventbuffer[i].Event.KeyEvent.bKeyDown == TRUE) {
|
|
|
|
/*check for special keys*/
|
|
|
|
switch (eventbuffer[i].Event.KeyEvent.wVirtualKeyCode) {
|
|
|
|
case VK_HOME:
|
|
|
|
return MP_KEY_HOME;
|
|
|
|
case VK_END:
|
|
|
|
return MP_KEY_END;
|
|
|
|
case VK_DELETE:
|
|
|
|
return MP_KEY_DEL;
|
|
|
|
case VK_INSERT:
|
|
|
|
return MP_KEY_INS;
|
|
|
|
case VK_BACK:
|
|
|
|
return MP_KEY_BS;
|
|
|
|
case VK_PRIOR:
|
|
|
|
return MP_KEY_PGUP;
|
|
|
|
case VK_NEXT:
|
|
|
|
return MP_KEY_PGDWN;
|
|
|
|
case VK_RETURN:
|
|
|
|
return MP_KEY_ENTER;
|
|
|
|
case VK_ESCAPE:
|
|
|
|
return MP_KEY_ESC;
|
|
|
|
case VK_LEFT:
|
|
|
|
return MP_KEY_LEFT;
|
|
|
|
case VK_UP:
|
|
|
|
return MP_KEY_UP;
|
|
|
|
case VK_RIGHT:
|
|
|
|
return MP_KEY_RIGHT;
|
|
|
|
case VK_DOWN:
|
|
|
|
return MP_KEY_DOWN;
|
|
|
|
case VK_SHIFT:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*check for function keys*/
|
|
|
|
if (0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode &&
|
|
|
|
eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
|
|
|
|
return MP_KEY_F + 1 +
|
|
|
|
eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70;
|
|
|
|
|
|
|
|
/*only characters should be remaining*/
|
|
|
|
//printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
|
|
|
|
return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOUSE_EVENT:
|
|
|
|
case WINDOW_BUFFER_SIZE_EVENT:
|
|
|
|
case FOCUS_EVENT:
|
|
|
|
case MENU_EVENT:
|
|
|
|
default:
|
|
|
|
//printf("getch2: unsupported event type");
|
|
|
|
break;
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|
2013-07-14 14:08:27 +00:00
|
|
|
return -1;
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 12:04:36 +00:00
|
|
|
bool getch2(struct input_ctx *ctx)
|
2007-08-25 04:28:08 +00:00
|
|
|
{
|
|
|
|
int r = getch2_internal();
|
|
|
|
if (r >= 0)
|
2013-07-14 14:08:27 +00:00
|
|
|
mp_input_put_key(ctx, r);
|
2012-04-06 11:24:26 +00:00
|
|
|
return true;
|
2007-08-25 04:28:08 +00:00
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
|
2013-07-14 14:08:27 +00:00
|
|
|
void getch2_poll(void)
|
|
|
|
{
|
2013-01-23 14:47:49 +00:00
|
|
|
}
|
|
|
|
|
2009-01-05 14:48:03 +00:00
|
|
|
void getch2_enable(void)
|
|
|
|
{
|
2013-07-14 14:08:27 +00:00
|
|
|
DWORD retval;
|
2010-02-27 21:50:59 +00:00
|
|
|
in = GetStdHandle(STD_INPUT_HANDLE);
|
2013-07-14 14:08:27 +00:00
|
|
|
if (!GetNumberOfConsoleInputEvents(in, &retval)) {
|
|
|
|
printf("getch2: %i can't get number of input events "
|
|
|
|
"[disabling console input]\n", (int)GetLastError());
|
|
|
|
getch2_status = 0;
|
|
|
|
} else
|
|
|
|
getch2_status = 1;
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
2009-01-05 14:48:03 +00:00
|
|
|
void getch2_disable(void)
|
|
|
|
{
|
2013-07-14 14:08:27 +00:00
|
|
|
if (!getch2_status)
|
|
|
|
return; // already disabled / never enabled
|
|
|
|
getch2_status = 0;
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|