⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keyboard_linux.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
字号:
/******************************************************************************
*******************************************************************************
**                                                                           **
**  Copyright (c) 2006 Videon Central, Inc.                                  **
**  All rights reserved.                                                     **
**                                                                           **
**  The computer program contained herein contains proprietary information   **
**  which is the property of Videon Central, Inc.  The program may be used   **
**  and/or copied only with the written permission of Videon Central, Inc.   **
**  or in accordance with the terms and conditions stipulated in the         **
**  agreement/contract under which the programs have been supplied.          **
**                                                                           **
*******************************************************************************
******************************************************************************/
/**
 * @file keyboard_linux.cpp
 *
 * $Revision: 1.3 $ 
 *
 * linux platform specific keyboard i/o
 *
 */

#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <time.h>
#include "vdvd_types.h"
#include "keyboard.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif



/********************************************************************************
                                 GLOBAL VARIABLES
 ********************************************************************************/

static long originalTerminalFlags   = 0;
static int  rawKeycode              =0;







/**
 *******************************************************************************
 *  Keyboard_Open prepares for keyboard input/output
 *
 *******************************************************************************/
void Keyboard_Open ( void )
{
    long            fileMode;
    struct termios  terminalSettings;

    tcgetattr(STDIN_FILENO,&terminalSettings);
    originalTerminalFlags = terminalSettings.c_lflag;
    
    // Turn off line buffering (ICANON) and local echo.
    terminalSettings.c_lflag &= (~(ICANON|ECHO));        

    tcsetattr(STDIN_FILENO,TCSANOW,&terminalSettings);

    fileMode= fcntl(STDIN_FILENO,F_GETFL);
    fileMode|= O_NDELAY;
    fcntl(STDIN_FILENO,F_SETFL,fileMode);
}






/**
 *******************************************************************************
 *  Keyboard_Close releases any resources obtained for keyboard input/output
 *
 *******************************************************************************/
void Keyboard_Close ( void )
{
    struct termios terminalSettings;

    tcgetattr(STDIN_FILENO,&terminalSettings);
    terminalSettings.c_lflag= originalTerminalFlags;
    tcsetattr(STDIN_FILENO,TCSANOW,&terminalSettings);
}






/**
 *******************************************************************************
 *  Keyboard_IsKeyAvailable checks if a key has been pressed on the keyboard
 *
 *  @return     TRUE if the keyboard has been pressed, FALSE otherwise
 *******************************************************************************/
BOOLEAN Keyboard_IsKeyAvailable( void )
{
    int     key;

    key = getchar();

    if ( key == -1 ) 
    {
        rawKeycode = 0;
        return (FALSE);
    }

    rawKeycode = key;
    if ( key == 0x1b )
    {
        key = getchar();
        if ( key != -1 ) 
        {
            rawKeycode = ((rawKeycode << 8) | key);
            if ( key == 0x5b )
            {
                key = getchar();
                if ( key != -1 ) 
                {
                    rawKeycode = ((rawKeycode << 8) | key);
                }
            }
        }
    }



    return ( TRUE );
}






/**
 *******************************************************************************
 *  Keyboard_GetKey returns next available key from keyboard.
 *  NOTE: This routine will block if no key is available until the keyboard is pressed
 *
 *  @return     keycode as a KeyboardKeycodeType
 *******************************************************************************/
KeyboardKeycodeType Keyboard_GetKey ( void )
{
    switch ( rawKeycode ) 
    {
        case 0x1b5b41:  return ( KEYBOARD_KEYCODE_UP_ARROW );
        case 0x1b5b42:  return ( KEYBOARD_KEYCODE_DOWN_ARROW );
        case 0x1b5b43:  return ( KEYBOARD_KEYCODE_RIGHT_ARROW );
        case 0x1b5b44:  return ( KEYBOARD_KEYCODE_LEFT_ARROW );
        case 13:        return ( KEYBOARD_KEYCODE_ENTER );
        case 10:        return ( KEYBOARD_KEYCODE_ENTER );
        case 32:        return ( KEYBOARD_KEYCODE_SPACEBAR );

        default:
            return ( (KeyboardKeycodeType)rawKeycode );
        break;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -