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>
|
2009-05-31 13:00:51 +00:00
|
|
|
#include <string.h>
|
2003-03-30 21:20:04 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include "keycodes.h"
|
2005-11-14 00:30:37 +00:00
|
|
|
#include "input/input.h"
|
2007-08-25 04:28:08 +00:00
|
|
|
#include "mp_fifo.h"
|
2008-04-29 11:52:45 +00:00
|
|
|
#include "getch2.h"
|
|
|
|
|
2007-03-04 18:55:44 +00:00
|
|
|
// HACK, stdin is used as something else below
|
|
|
|
#undef stdin
|
2003-09-22 11:31:51 +00:00
|
|
|
|
2008-02-21 16:15:31 +00:00
|
|
|
int mp_input_slave_cmd_func(int fd,char* dest,int size){
|
2004-08-13 13:32:43 +00:00
|
|
|
DWORD retval;
|
2003-09-22 11:31:51 +00:00
|
|
|
HANDLE stdin = GetStdHandle(STD_INPUT_HANDLE);
|
2004-08-13 13:32:43 +00:00
|
|
|
if(!PeekNamedPipe(stdin, NULL, size, &retval, NULL, NULL) || !retval){
|
|
|
|
return MP_INPUT_NOTHING;
|
2003-09-22 11:31:51 +00:00
|
|
|
}
|
2004-08-13 13:32:43 +00:00
|
|
|
if(retval>size)retval=size;
|
|
|
|
ReadFile(stdin, dest, retval, &retval, NULL);
|
|
|
|
if(retval)return retval;
|
2003-09-22 11:31:51 +00:00
|
|
|
return MP_INPUT_NOTHING;
|
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
|
|
|
|
int screen_width=80;
|
|
|
|
int screen_height=24;
|
2005-12-29 11:27:22 +00:00
|
|
|
char * erase_to_end_of_line = NULL;
|
2003-03-30 21:20:04 +00:00
|
|
|
|
2009-01-05 14:48:03 +00:00
|
|
|
void get_screen_size(void){
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HANDLE stdin;
|
2003-04-19 09:19:30 +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)
|
|
|
|
{
|
2003-03-30 21:20:04 +00:00
|
|
|
INPUT_RECORD eventbuffer[128];
|
|
|
|
DWORD retval;
|
|
|
|
int i=0;
|
2009-07-06 23:26:13 +00:00
|
|
|
if(!getch2_status)return -1;
|
2003-03-30 21:20:04 +00:00
|
|
|
/*check if there are input events*/
|
|
|
|
if(!GetNumberOfConsoleInputEvents(stdin,&retval))
|
|
|
|
{
|
|
|
|
printf("getch2: can't get number of input events: %i\n",GetLastError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(retval<=0)return -1;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
|
|
|
/*read all events*/
|
2003-03-30 21:20:04 +00:00
|
|
|
if(!ReadConsoleInput(stdin,eventbuffer,128,&retval))
|
|
|
|
{
|
|
|
|
printf("getch: can't read input events\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-03-30 21:20:04 +00:00
|
|
|
/*filter out keyevents*/
|
2009-07-06 23:26:13 +00:00
|
|
|
for (i = 0; i < retval; i++)
|
2003-03-30 21:20:04 +00:00
|
|
|
{
|
2009-07-06 23:26:13 +00:00
|
|
|
switch(eventbuffer[i].EventType)
|
2003-03-30 21:20:04 +00:00
|
|
|
{
|
|
|
|
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 KEY_HOME;
|
|
|
|
case VK_END:
|
|
|
|
return KEY_END;
|
|
|
|
case VK_DELETE:
|
|
|
|
return KEY_DEL;
|
|
|
|
case VK_INSERT:
|
|
|
|
return KEY_INS;
|
|
|
|
case VK_BACK:
|
|
|
|
return KEY_BS;
|
|
|
|
case VK_PRIOR:
|
|
|
|
return KEY_PGUP;
|
|
|
|
case VK_NEXT:
|
|
|
|
return KEY_PGDWN;
|
|
|
|
case VK_RETURN:
|
|
|
|
return KEY_ENTER;
|
|
|
|
case VK_ESCAPE:
|
|
|
|
return KEY_ESC;
|
|
|
|
case VK_LEFT:
|
|
|
|
return KEY_LEFT;
|
|
|
|
case VK_UP:
|
|
|
|
return KEY_UP;
|
|
|
|
case VK_RIGHT:
|
|
|
|
return KEY_RIGHT;
|
|
|
|
case VK_DOWN:
|
|
|
|
return KEY_DOWN;
|
2003-06-01 12:33:32 +00:00
|
|
|
case VK_SHIFT:
|
2009-07-06 23:26:13 +00:00
|
|
|
continue;
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|
|
|
|
/*check for function keys*/
|
2006-04-15 21:18:20 +00:00
|
|
|
if(0x87 >= eventbuffer[i].Event.KeyEvent.wVirtualKeyCode && eventbuffer[i].Event.KeyEvent.wVirtualKeyCode >= 0x70)
|
2008-05-16 09:42:28 +00:00
|
|
|
return KEY_F + 1 + eventbuffer[i].Event.KeyEvent.wVirtualKeyCode - 0x70;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-03-30 21:20:04 +00:00
|
|
|
/*only characters should be remaining*/
|
2009-07-06 23:26:13 +00:00
|
|
|
//printf("getch2: YOU PRESSED \"%c\" \n",eventbuffer[i].Event.KeyEvent.uChar.AsciiChar);
|
2003-03-30 21:20:04 +00:00
|
|
|
return eventbuffer[i].Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
break;
|
|
|
|
|
2003-03-30 21:20:04 +00:00
|
|
|
case MOUSE_EVENT:
|
2009-07-06 23:26:13 +00:00
|
|
|
case WINDOW_BUFFER_SIZE_EVENT:
|
|
|
|
case FOCUS_EVENT:
|
2003-03-30 21:20:04 +00:00
|
|
|
case MENU_EVENT:
|
|
|
|
default:
|
2009-07-06 23:26:13 +00:00
|
|
|
//printf("getch2: unsupported event type");
|
|
|
|
break;
|
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:12:19 +00:00
|
|
|
void getch2(struct mp_fifo *fifo)
|
2007-08-25 04:28:08 +00:00
|
|
|
{
|
|
|
|
int r = getch2_internal();
|
|
|
|
if (r >= 0)
|
2008-04-29 12:12:19 +00:00
|
|
|
mplayer_put_key(fifo, r);
|
2007-08-25 04:28:08 +00:00
|
|
|
}
|
2003-03-30 21:20:04 +00:00
|
|
|
|
2009-01-05 14:48:03 +00:00
|
|
|
void getch2_enable(void)
|
|
|
|
{
|
2003-04-25 10:00:18 +00:00
|
|
|
DWORD retval;
|
2003-04-19 09:19:30 +00:00
|
|
|
stdin = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
if(!GetNumberOfConsoleInputEvents(stdin,&retval))
|
|
|
|
{
|
|
|
|
printf("getch2: %i can't get number of input events [disabling console input]\n",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)
|
|
|
|
{
|
2003-03-30 21:20:04 +00:00
|
|
|
if(!getch2_status) return; // already disabled / never enabled
|
|
|
|
getch2_status=0;
|
|
|
|
}
|
|
|
|
|
2008-08-07 10:36:07 +00:00
|
|
|
#ifdef CONFIG_ICONV
|
2007-03-04 19:04:08 +00:00
|
|
|
static const struct {
|
|
|
|
unsigned cp;
|
|
|
|
char* alias;
|
|
|
|
} cp_alias[] = {
|
|
|
|
{ 20127, "ASCII" },
|
|
|
|
{ 20866, "KOI8-R" },
|
|
|
|
{ 21866, "KOI8-RU" },
|
|
|
|
{ 28591, "ISO-8859-1" },
|
|
|
|
{ 28592, "ISO-8859-2" },
|
|
|
|
{ 28593, "ISO-8859-3" },
|
|
|
|
{ 28594, "ISO-8859-4" },
|
|
|
|
{ 28595, "ISO-8859-5" },
|
|
|
|
{ 28596, "ISO-8859-6" },
|
|
|
|
{ 28597, "ISO-8859-7" },
|
|
|
|
{ 28598, "ISO-8859-8" },
|
|
|
|
{ 28599, "ISO-8859-9" },
|
|
|
|
{ 28605, "ISO-8859-15" },
|
|
|
|
{ 65001, "UTF-8" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2007-04-01 21:59:54 +00:00
|
|
|
char* get_term_charset(void)
|
2007-03-04 19:04:08 +00:00
|
|
|
{
|
2009-05-31 13:00:51 +00:00
|
|
|
char codepage[10];
|
2007-03-04 19:04:08 +00:00
|
|
|
unsigned i, cpno = GetConsoleOutputCP();
|
|
|
|
if (!cpno)
|
|
|
|
cpno = GetACP();
|
|
|
|
if (!cpno)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; cp_alias[i].cp; i++)
|
|
|
|
if (cpno == cp_alias[i].cp)
|
2009-05-31 13:00:51 +00:00
|
|
|
return strdup(cp_alias[i].alias);
|
2007-03-04 19:04:08 +00:00
|
|
|
|
|
|
|
snprintf(codepage, sizeof(codepage), "CP%u", cpno);
|
2009-05-31 13:00:51 +00:00
|
|
|
return strdup(codepage);
|
2007-03-04 19:04:08 +00:00
|
|
|
}
|
|
|
|
#endif
|