📄 textkbd___.c
字号:
/*
* Start of Zoran Standard Header
* Copyright (c) 2005 Zoran Corporation
*
*
* All rights reserved. Proprietary and confidential.
*
* DESCRIPTION for textkbd.c
* Combo-board keyboard interface for text-only user-interface.
*
* NEW HISTORY COMMENT (description must be followed by a blank line)
* <Enter change description here>
* ===== HISTORY of changes in //depot/imgeng/sw/se_gw/ui/fs/comboui/textkbd.c
*
* 17/Aug/05 #4 dstrauss Reduce key-down repeat time to 1/2 second.
* Use programmable keys to generate left-, right-,
* and menu-combo key events.
* 16/Aug/05 #3 dstrauss Renamed KybdInit to TextKbdInit to avoid conflict.
* 16/Aug/05 #2 dstrauss Hook into the (new) low-level keyboard handler.
* 5/Aug/05 #1 dstrauss Created. Stub routines for now.
*
* End of Zoran Standard Header
*/
#include "univ.gh"
#include "arch.h"
#include "pile.h"
#include "dbg.h"
#include "standard.h"
#include "ts.h"
#include "uimisc.h"
#include "uikbd.h"
#include "kbdif.h"
#include "textkbd.h"
#define OLDKEY_MENU 0x00
#define OLDKEY_LEFT 0x01
#define OLDKEY_RIGHT 0x02
#define OLDKEY_SELECT 0x03
#define OLDKEY_COPIES 0x04
#define OLDKEY_SCALE 0x05
#define OLDKEY_BRIGHTNESS 0x06
#define OLDKEY_PAPERTYPE 0x07
#define OLDKEY_QUALITY 0x08
#define OLDKEY_MODE 0x0a
#define OLDKEY_MONOCOPY 0x0c
#define OLDKEY_COLORCOPY 0x0d
#define OLDKEY_SCAN 0x0e
#define OLDKEY_CANCEL 0x0f
#define KEYBUF_SIZE 32 /* MUST be a power of 2! */
static Uint8 keybuf[KEYBUF_SIZE];
static Uint32 keybufInCount;
static Uint32 keybufOutCount;
static tsSemaphore kSem; /* old keyboard handler semaphore */
static Uint32 keypressTime;
/******************************************************************************
* Name: KybdGetKeyDownTime
*
* Description: Return the amount of time (in milliseconds) that the same key
* has been pressed.
*
* Parameters: pDownTime - pointer to a variable to hold the key down time.
*
* Return: API_OK - command succeeded.
* API_FAIL - command failed.
* - keyboard not initialized
* - unable to get or release the api semaphore
*
* Notes: Use of this API is deprecated.
******************************************************************************/
API_RET KybdGetKeyDownTime(Uint32* pDownTime)
{
int keycount;
TASKSEMWAIT(kSem);
keycount = keybufInCount - keybufOutCount;
if (keycount || (keypressTime == 0) ) {
/* if there are still unread key presses in the buffer, the
* "down time" is effectively zero.
*/
*pDownTime = 0;
} else {
/* repeat if the button is held down for more than 1/2 second */
*pDownTime = (TaskGetSystemMilliTicks() - keypressTime)/500;
}
TASKSEMSIGNAL(kSem);
return API_OK;
}
/******************************************************************************
* Name: KybdHits
*
* Description: Check if any keys have been pressed.
*
* Parameters: pNumKeys - pointer to a variable to hold the number of keys
* in the keyboard buffer.
*
* Return: API_OK - command succeeded.
* API_FAIL - command failed.
* - keyboard not initialized
* - unable to get or release the api semaphore
*
* Notes: Use of this API is deprecated.
******************************************************************************/
API_RET KybdHits(Uint8* pNumKeys)
{
TASKSEMWAIT(kSem);
*pNumKeys = keybufInCount - keybufOutCount;
TASKSEMSIGNAL(kSem);
return (API_OK);
}
/******************************************************************************
* Name: KybdGetKey
*
* Description: Read a key code from the keyboard buffer.
*
* Parameters: pCode - pointer to a variable to hold the key code:
* - KYBD_NO_KEY (0xFF) if no key was available before
* timeout
* - key code (0..63) of the key pressed
* timeout - the amount of time the procedure will wait (in ticks)
* for a key to be pressed. A timeout of '0' will wait
* forever.
*
* Return: API_OK - command succeeded.
* API_FAIL - command failed.
* - keyboard not initialized
* - unable to get or release the api semaphore
*
* Notes: Use of this API is deprecated.
******************************************************************************/
API_RET KybdGetKey(Uint8* pCode, Uint32 timeout)
{
TASKSEMWAIT(kSem);
if (keybufInCount > keybufOutCount) {
*pCode = keybuf[keybufOutCount % KEYBUF_SIZE];
keybufOutCount++;
} else {
*pCode = KYBD_NO_KEY;
}
TASKSEMSIGNAL(kSem);
return(API_OK);
}
static void kybdHandler(Uint32 keycode)
{
Uint8 oldkey;
/* convert new key codes into old (legacy) key codes */
switch (keycode) {
case (KEY_MONOCOPY|KEY_IS_DOWN):
oldkey = OLDKEY_MONOCOPY;
break;
case (KEY_CANCEL|KEY_IS_DOWN):
oldkey = OLDKEY_CANCEL;
break;
case (KEY_COLORCOPY|KEY_IS_DOWN):
oldkey = OLDKEY_COLORCOPY;
break;
case (KEY_COLORSCAN|KEY_IS_DOWN):
/* colorscan is the same as monoscan on the old UI */
case (KEY_MONOSCAN|KEY_IS_DOWN):
oldkey = OLDKEY_SCAN;
break;
case (KEY_QUALITY|KEY_IS_DOWN):
oldkey = OLDKEY_QUALITY;
break;
case (KEY_MODE|KEY_IS_DOWN):
oldkey = OLDKEY_MODE;
break;
case (KEY_COPIES|KEY_IS_DOWN):
oldkey = OLDKEY_COPIES;
break;
case (KEY_SCALE|KEY_IS_DOWN):
oldkey = OLDKEY_SCALE;
break;
case (KEY_BRIGHTNESS|KEY_IS_DOWN):
oldkey = OLDKEY_BRIGHTNESS;
break;
case (KEY_PAPERTYPE|KEY_IS_DOWN):
oldkey = OLDKEY_PAPERTYPE;
break;
case (KEY_MENU|KEY_IS_DOWN):
oldkey = OLDKEY_MENU;
break;
case (KEY_LEFT|KEY_IS_DOWN):
oldkey = OLDKEY_LEFT;
break;
case (KEY_RIGHT|KEY_IS_DOWN):
oldkey = OLDKEY_RIGHT;
break;
case (KEY_SELECT|KEY_IS_DOWN):
oldkey = OLDKEY_SELECT;
break;
case (KEY_PROG1|KEY_IS_DOWN):
oldkey = KEY_COMBO_LEFT;
break;
case (KEY_PROG2|KEY_IS_DOWN):
oldkey = KEY_COMBO_RIGHT;
break;
case (KEY_PROG3|KEY_IS_DOWN):
oldkey = KEY_COMBO_MENU;
break;
case (KEY_MONOCOPY):
case (KEY_CANCEL):
case (KEY_COLORCOPY):
case (KEY_COLORSCAN):
case (KEY_MONOSCAN):
case (KEY_QUALITY):
case (KEY_MODE):
case (KEY_COPIES):
case (KEY_SCALE):
case (KEY_BRIGHTNESS):
case (KEY_PAPERTYPE):
case (KEY_MENU):
case (KEY_LEFT):
case (KEY_RIGHT):
case (KEY_SELECT):
case (KEY_PROG1):
case (KEY_PROG2):
case (KEY_PROG3):
/* Assume all key-up events match a single key-down event. This
* isn't necessarily true but it's close enough to work for the
* routine that checks on this.
*/
keypressTime = 0;
default: /* do nothing for all the other keys */
return;
}
if ((keybufInCount - keybufOutCount) >= KEYBUF_SIZE) {
/* drop any keys as long as the buffer is full */
return;
}
/* latch the time the key was pressed */
keypressTime = TaskGetSystemMilliTicks();
/* save the key code */
keybuf[keybufInCount % KEYBUF_SIZE] = oldkey;
keybufInCount++;
}
/************************************************************
*
************************************************************/
void TextKbdInit(void)
{
API_RET retval;
kSem = TASKSEMCREATE(1);
retval = KBDIFRegisterKeyHandler(kybdHandler);
ASSERT(retval == API_OK);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -