📄 key.cpp
字号:
#include <cctype>
#include "strutils.h"
#include "key.h"
#include "keyqueue.h" // from cmu package
Key::Key()
: myChar(0),
myKind(ascii)
{
}
Key::Key(char ch)
: myChar(ch),
myKind(ascii)
{
}
Key::Key(char ch, Key::Kind k)
: myChar(ch),
myKind(k)
{
}
bool operator == (const Key& lhs, const Key& rhs)
{
return lhs.aschar() == rhs.aschar() &&
lhs.getKind() == rhs.getKind();
}
bool operator != (const Key& lhs, const Key& rhs)
{
return ! (lhs == rhs);
}
Key::Kind Key::getKind() const
{
return myKind;
}
bool Key::isnothing() const
{
return myKind == none;
}
bool Key::isfunction() const
{
return myKind == function;
}
bool Key::isarrow() const
{
return myKind == arrow;
}
bool Key::isescape() const
{
return myKind == escape;
}
bool Key::iscontrol() const
{
return myKind == ascii && iscntrl(myChar);
}
bool Key::isasc() const
{
return myKind == ascii;
}
char Key::aschar() const
{
return myChar;
}
bool Key::isleftarrow() const
{
return myKind == arrow && myChar == 4;
}
bool Key::isrightarrow() const
{
return myKind == arrow && myChar == 6;
}
bool Key::isuparrow() const
{
return myKind == arrow && myChar == 8;
}
bool Key::isdownarrow() const
{
return myKind == arrow && myChar == 2;
}
bool Key::ishome() const
{
return myKind == arrow && myChar == 7;
}
bool Key::isend() const
{
return myKind == arrow && myChar == 1;
}
bool Key::ispageup() const
{
return myKind == arrow && myChar == 9;
}
bool Key::ispagedown() const
{
return myKind == arrow && myChar == 3;
}
bool Key::iscenter() const
{
return myKind == arrow && myChar == 5;
}
int Key::funkey() const
{
if (myKind != function) return -1;
return myChar;
}
string Key::tostring() const
{
static string arrowkeys[] =
{
"dummy","end","down","pagedown","left","center",
"right","home","up","pageup"
};
if (isasc() && isprint(myChar))
return string("") + myChar;
if (isfunction())
return string("function F") + ::tostring(myChar);
if (isarrow())
return string("arrow ") + arrowkeys[myChar];
if (isescape())
return "escape";
if (iscontrol())
return string("control ") + char('a'+myChar-1);
return string("") + myChar;
}
ostream& operator << (ostream& output, const Key& k)
{
output << k.tostring();
return output;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -