kbdist.cpp

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 522 行 · 第 1/2 页

CPP
522
字号
/* -*-C-*-
 *
 * $Revision: 1.5 $
 *   $Author: kwelton $
 *     $Date: 2000/07/14 23:06:03 $
 *
 * @module keybdist.cpp
 *
 *    This file implements the interrupt service thread part of the platform
 *    independent code of the keyboard driver.  This is provided as a sample
 *    to platform driver writers and is expected to be able to be used without
 *    major modification on most hardware platforms.
 *
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
 * ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 *
 * Copyright (c) 1995-1998  Microsoft Corporation
 * Copyright (c) 2000 ARM Limited
 * All Rights Reserved
 */

#include <windows.h>
#include <nkintr.h>
#include <keybddr.h>
#include <keybdpdd.h>

#include <ceddk.h>

#include "pl050keybd.hpp"

#ifdef DEBUG
DBGPARAM dpCurSettings =
{
    TEXT("Keybd"),
    {
        TEXT("Undefined"), TEXT("Undefined"),
        TEXT("Undefined"), TEXT("Undefined"),
        TEXT("Undefined"), TEXT("Undefined"),
        TEXT("Undefined"), TEXT("Undefined"),
        TEXT("Undefined"), TEXT("Undefined"),
        TEXT("Undefined"), TEXT("Undefined"),
        TEXT("Undefined"), TEXT("Undefined"),
        TEXT("Undefined"), TEXT("Undefined")
    },
    0x00000000 };
#endif /* def DEBUG */

// Auto repeat #defines and state variables.
#define AR_WAIT_FOR_ANY         0
#define AR_INITIAL_DELAY        1
#define AR_AUTOREPEATING        2
#define AR_AUTO_PARTIAL         3       // Auto repeat was interrupted by
                                        // real PDD event.

#define AUTO_REPEAT_INITIAL_DELAY_MIN           250
#define AUTO_REPEAT_INITIAL_DELAY_MAX           1000
#define AUTO_REPEAT_INITIAL_DELAY_DEFAULT       500

#define AUTO_REPEAT_KEYS_PER_SEC_MIN            2
#define AUTO_REPEAT_KEYS_PER_SEC_MAX            30
#define AUTO_REPEAT_KEYS_PER_SEC_DEFAULT        20

static volatile int v_AutoRepeatState = AR_WAIT_FOR_ANY;
static DWORD v_AutoRepeatInitialDelay = AUTO_REPEAT_INITIAL_DELAY_DEFAULT;
static DWORD v_AutoRepeatKeysPerSec = AUTO_REPEAT_KEYS_PER_SEC_DEFAULT;
static UINT32 v_AutoRepeatVKey;
static UINT32 v_AutoRepeatScanCode;
static KEY_STATE_FLAGS v_AutoRepeatKeyStateFlags;

// Routine to call back in to user when there is a keyboard event.
PFN_KEYBD_EVENT_CALLBACK_EX v_pfnKeybdEventCallbackEx = NULL;

/*
 * @func KeybdDriverGetInfo
 *
 *    Gives information about the keyboard and driver.
 *
 * @parms
 *
 *     iKeybdId     Id of the keyboard to get the information from.
 *     iIndex       Id of info to retrieve.
 *     lpOutput     Output buffer.
 *
 * @rdesc
 *
 *    If the function succeeds the return value is TRUE, otherwise, it is
 *    FALSE.  Extended error information is available via the GetLastError
 *    function.
 *
 * @xref
 *
 *    KBDI_VKEY_TO_UNICODE_INFO_ID
 *    KBDI_AUTOREPEAT_INFO_ID
 *    KBDI_AUTOREPEAT_SELECTIONS_INFO_ID
 *
 * @comm
 *
 *    This function must be re-entrant since it is exposed by the input
 *    system via the <f KeybdGetDeviceInfo> function and may be called by
 *    multiple threads.
 */
extern "C" BOOL KeybdDriverGetInfo(INT iKeybdId, INT iIndex, LPVOID lpOutput)
{
    if (lpOutput == NULL)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

    switch (iIndex)
    {
      case KBDI_VKEY_TO_UNICODE_INFO_ID:
          VKeyToUnicodeInfo((struct KBDI_VKEY_TO_UNICODE_INFO*)lpOutput);
          break;

      case KBDI_AUTOREPEAT_INFO_ID:
      {
          struct KBDI_AUTOREPEAT_INFO *pInfo =
              (struct KBDI_AUTOREPEAT_INFO*)lpOutput;

          pInfo->CurrentInitialDelay = v_AutoRepeatInitialDelay;
          pInfo->CurrentRepeatRate = v_AutoRepeatKeysPerSec;
          pInfo->cInitialDelaysSelectable = -1;
          pInfo->cRepeatRatesSelectable = -1;
      }
      break;

      case KBDI_AUTOREPEAT_SELECTIONS_INFO_ID:
      {
          INT32 *pInfo = (INT32*)lpOutput;

          // Min initial delay
          *pInfo = AUTO_REPEAT_INITIAL_DELAY_MIN;

          // Max initial delay
          *(pInfo + 1) = AUTO_REPEAT_INITIAL_DELAY_MAX;

          // Min repeat rate
          *(pInfo + 2) = AUTO_REPEAT_KEYS_PER_SEC_MIN;

          // Max repeat rate
          *(pInfo + 3) = AUTO_REPEAT_KEYS_PER_SEC_MAX;
      }
      break;

      default:
          SetLastError(ERROR_INVALID_PARAMETER);
          return FALSE;
    }

    return TRUE;
}

#ifdef DEBUG
PFN_KEYBD_DRIVER_GET_INFO v_pfnGetInfoTest = KeybdDriverGetInfo;
#endif

/*
 * @func
 *
 * Sets information about the keyboard device.
 *
 * @parms
 *
 *    iKeybdId      Id of the keyboard to set the information
 *    iIndex        Id of info to set
 *    lpInput       Input buffer.
 *
 * @rdesc
 *
 *    If the function succeeds the return value is TRUE, otherwise, it is
 *    FALSE. Extended error information is available via the GetLastError
 *    function.
 *
 * @xref
 *
 *    KeybdDriverGetInfo
 *    KBDI_AUTOREPEAT_INFO_ID
 */
extern "C" BOOL KeybdDriverSetMode(INT iKeybdId, INT iIndex, LPVOID lpInput)
{
    if (lpInput == NULL)
    {
        SetLastError(ERROR_INVALID_PARAMETER);

        return FALSE;
    }

    switch (iIndex)
    {
      case KBDI_AUTOREPEAT_INFO_ID:
      {
          struct KBDI_AUTOREPEAT_INFO *pInfo =
              (struct KBDI_AUTOREPEAT_INFO*)lpInput;

          if (pInfo->CurrentInitialDelay > AUTO_REPEAT_INITIAL_DELAY_MAX)
          {
#if 0
              RETAILMSG(1, (TEXT("Initial delay too large, using %d\r\n"),
                            AUTO_REPEAT_INITIAL_DELAY_MAX));
#endif /* 0/1 */

              v_AutoRepeatInitialDelay = AUTO_REPEAT_INITIAL_DELAY_MAX;
          }
          else if (pInfo->CurrentInitialDelay < AUTO_REPEAT_INITIAL_DELAY_MIN)
          {
#if 0
              RETAILMSG(1, (TEXT("Initial delay too small, using %d\r\n"),
                            AUTO_REPEAT_INITIAL_DELAY_MIN));
#endif /* 0/1 */

              v_AutoRepeatInitialDelay = AUTO_REPEAT_INITIAL_DELAY_MIN;
          }
          else
              v_AutoRepeatInitialDelay = pInfo->CurrentInitialDelay;

          if (pInfo->CurrentRepeatRate > AUTO_REPEAT_KEYS_PER_SEC_MAX)
          {
#if 0
              RETAILMSG(1,
                        (TEXT("Initial repeat rate too large, using %d\r\n"),
                         AUTO_REPEAT_KEYS_PER_SEC_MAX));
#endif /* 0/1 */

              v_AutoRepeatKeysPerSec = AUTO_REPEAT_KEYS_PER_SEC_MAX;
          }
          else if ((pInfo->CurrentRepeatRate < AUTO_REPEAT_KEYS_PER_SEC_MIN) &&
                   (pInfo->CurrentRepeatRate != 0))
          {
#if 0
              RETAILMSG(1,
                        (TEXT("Initial repeat rate too small, using %d\r\n"),
                         AUTO_REPEAT_KEYS_PER_SEC_MIN));
#endif /* 0/1 */

              v_AutoRepeatKeysPerSec = AUTO_REPEAT_KEYS_PER_SEC_MIN;
          }
          else
              v_AutoRepeatKeysPerSec = pInfo->CurrentRepeatRate;
      }
      break;

      default:
          SetLastError(ERROR_INVALID_PARAMETER);
          return FALSE;
    }

    return TRUE;
}

#ifdef DEBUG
PFN_KEYBD_DRIVER_SET_MODE v_pfnSetModeTest = KeybdDriverSetMode;
#endif

extern "C" unsigned int KbdISRUpcall(bool timedout, unsigned int scancode)
{
    /*
     * these three variables are all hardcoded with the PDD
     */

⌨️ 快捷键说明

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