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

📄 keyev.cpp

📁 使用BorlandC++4.5编译的一个MUD客户端程序
💻 CPP
字号:
// keyev.cpp
//
// $Id: keyev.cpp 2.2 1995/10/30 18:25:34 tsurace Beta $
// $Log: keyev.cpp $// Revision 2.2  1995/10/30  18:25:34  tsurace// Tied function keys and shift-fkey combinations to VT-style// macros.//
// Revision 2.1  1995/10/24  15:52:51  tsurace
// Roll.
//
// Revision 1.2  1995/10/11  21:04:34  tsurace
// Changed from assert() to ASSERT() macros.
//
// Revision 1.1  1995/10/02  00:53:52  tsurace
// Initial revision
//
//
#define  STRICT
#include "windows.h"
#pragma hdrstop

#include "debug.hpp"   // ASSERT
#include "keyev.hpp"
#include "resids.hpp"  // macros loaded from resource
#include "vt102em.hpp" // scream_and_die

// >>>>> KeyEvent <<<<< //

// Constructor
//
// This assumes that one KeyEvent is generated for each one of the repeat
// count, therefore one KeyEvent represents ONE of the repeat values

CharKeyEvent::CharKeyEvent(WPARAM wParam)
{
    ASSERT(wParam > 0 && wParam < 256, "Key is not ascii");
    
    _buffer[0] = (char)wParam;
    _buffer[1] = '\0'; 

    if (_buffer[0] == '\r') // unix compatibility: translate CR into NL
        _buffer[0] = '\n';
}

// ---------------------------------------
// >>>>> AcceleratorKeyEvent methods <<<<< 
// ---------------------------------------

// ------------------------------------------------------------------------
// _map - this is the key map
//
// This maps function keys and accelerators to strings that will be sent
// to VaporTalk.  Some keys map to VT102 keys, others (such as Function
// keys) map to functions.
//
const size_t AcceleratorKeyEvent::_mapSize = 38;
AcceleratorKeyEvent::_KeyMapEntry
AcceleratorKeyEvent::_map[AcceleratorKeyEvent::_mapSize] =
{
{ACC_Up,              "\x01B[A"},
{ACC_Down,            "\x01B[B"},
{ACC_Left,            "\x01B[D"},
{ACC_Right,           "\x01B[C"},
{ACC_Home,            "\x01B[H"},
{ACC_End,             "\x01B[K"},
{ACC_Delete,          "\x004"},     // ^D is delete char
{ACC_F1,              "/F1\n"},
{ACC_F2,              "/F2\n"},
{ACC_F3,              "/F3\n"},
{ACC_F4,              "/F4\n"},
{ACC_F5,              "/F5\n"},
{ACC_F6,              "/F6\n"},
{ACC_F7,              "/F7\n"},
{ACC_F8,              "/F8\n"},
{ACC_F9,              "/F9\n"},
{ACC_F10,             "/F10\n"},
{ACC_ShiftF1,              "/ShiftF1\n"},
{ACC_ShiftF2,              "/ShiftF2\n"},
{ACC_ShiftF3,              "/ShiftF3\n"},
{ACC_ShiftF4,              "/ShiftF4\n"},
{ACC_ShiftF5,              "/ShiftF5\n"},
{ACC_ShiftF6,              "/ShiftF6\n"},
{ACC_ShiftF7,              "/ShiftF7\n"},
{ACC_ShiftF8,              "/ShiftF8\n"},
{ACC_ShiftF9,              "/ShiftF9\n"},
{ACC_ShiftF10,             "/ShiftF10\n"},
{ACC_ControlF1,              "/CtrlF1\n"},
{ACC_ControlF2,              "/CtrlF2\n"},
{ACC_ControlF3,              "/CtrlF3\n"},
{ACC_ControlF4,              "/CtrlF4\n"},
{ACC_ControlF5,              "/CtrlF5\n"},
{ACC_ControlF6,              "/CtrlF6\n"},
{ACC_ControlF7,              "/CtrlF7\n"},
{ACC_ControlF8,              "/CtrlF8\n"},
{ACC_ControlF9,              "/CtrlF9\n"},
{ACC_ControlF10,             "/CtrlF10\n"}
};

// ------------------------------------------------------------------------
// constructor - convert WM_COMMAND to keystroke
//
// Parameters:
//   id - the wParam passed with this event
//
AcceleratorKeyEvent::AcceleratorKeyEvent(WPARAM wParam)
{
    int id = LOWORD(wParam); // accelerator/menu id
    
    // Do a simple sequential search for the entry
    size_t i = 0;
    while (1) // loop forever
    {
        if (i >= _mapSize)
        {
            ASSERT(0, "Unexpected accelerator key!");
            _buffer[0] = '\0';
            break;
        }
        else if (id == _map[i].id)
        {
            // Copy string to buffer.
            // Copying allows several instances of the AcceleratorKeyEvent to
            // exist simultaneously, where pointer assignment would not.
            
            strcpy(_buffer, _map[i].string);
            break;
        }
        else
            ++ i;
    };
};

// EOF //

⌨️ 快捷键说明

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