Permalink
Browse files

Raw keycodes

  • Loading branch information...
mlang committed Jul 28, 2017
1 parent 424678d commit 8b837ffe7a5603efd7d17a1e86110643abf8b0e7
Showing with 42 additions and 3 deletions.
  1. +3 −0 brltest.cpp
  2. +21 −2 lib/brlapi.cpp
  3. +18 −1 lib/brlapi.hpp
View
@@ -16,6 +16,9 @@ int main() {
std::stringstream Text;
Text << "You are on tty" << TTY.number();
TTY.writeText(Text);
auto KeyCode = TTY.readKey();
Text << " and pressed key " << KeyCode.group() << " " << KeyCode.number() << " " << KeyCode.press();
TTY.writeText(Text);
std::this_thread::sleep_for(5s);
}
}
View
@@ -54,12 +54,24 @@ void BrlAPI::TTY::writeText(std::string Text) {
}
}
std::uint64_t BrlAPI::TTY::readKey() const {
BrlAPI::KeyCode BrlAPI::TTY::readKey() const {
brlapi_keyCode_t Key;
if (brlapi__readKey(Conn->BrlAPI->handle(), 1, &Key) == -1) {
throw std::system_error(brlapi_errno, std::generic_category());
}
return Key;
return { Key };
}
bool BrlAPI::TTY::readKey(KeyCode &KeyCode) const {
brlapi_keyCode_t Key;
auto Result = brlapi__readKey(Conn->BrlAPI->handle(), 0, &Key);
if (Result == -1) {
throw std::system_error(brlapi_errno, std::generic_category());
}
if (Result == 1) {
KeyCode = BrlAPI::KeyCode(Key);
}
return Result == 1;
}
BrlAPI::Connection::Connection() : BrlAPI(std::make_unique<Implementation>()) {
@@ -94,6 +106,13 @@ BrlAPI::TTY BrlAPI::Connection::tty(int TTY, bool Raw) {
if (Number == -1) {
throw std::system_error(brlapi_errno, std::generic_category());
}
brlapi_range_t Ranges[] = {
{ 0, std::numeric_limits<brlapi_keyCode_t>::max() }
};
brlapi__acceptKeyRanges(
BrlAPI->handle(),
Ranges, std::distance(std::begin(Ranges), std::end(Ranges))
);
return { this, Number };
}
View
@@ -22,6 +22,22 @@ std::ostream &operator<<(std::ostream &, DisplaySize const &);
class Connection;
class KeyCode {
std::uint8_t Group, Number;
bool Press;
friend class TTY;
KeyCode(std::uint64_t Code)
: Group((Code >> 8) & 0b11111111)
, Number(Code & 0b11111111)
, Press(Code >> 63) {}
public:
auto group() const noexcept { return Group; }
auto number() const noexcept { return Number; }
auto press() const noexcept { return Press; }
};
class TTY {
Connection *Conn;
int Number;
@@ -43,7 +59,8 @@ class TTY {
void writeText(std::string);
void writeText(std::stringstream const &Stream) { writeText(Stream.str()); }
std::uint64_t readKey() const;
KeyCode readKey() const;
bool readKey(KeyCode &) const;
};
class Connection {

0 comments on commit 8b837ff

Please sign in to comment.