Last active
December 17, 2015 11:38
-
-
Save jvcleave/5603227 to your computer and use it in GitHub Desktop.
get keypress from SSH terminal in OF/RPi app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include "ofMain.h" | |
| class SSHKeyListenerEventData | |
| { | |
| public: | |
| SSHKeyListenerEventData(char character_) | |
| { | |
| character = character_; | |
| } | |
| char character; | |
| }; | |
| class SSHKeyListener | |
| { | |
| public: | |
| virtual void onCharacterReceived(SSHKeyListenerEventData& e) = 0; | |
| }; | |
| class ConsoleListener: public ofThread | |
| { | |
| public: | |
| SSHKeyListener* listener; | |
| ConsoleListener() | |
| { | |
| listener = NULL; | |
| } | |
| void setup(SSHKeyListener* listener_) | |
| { | |
| listener = listener_; | |
| startThread(false, true); | |
| } | |
| void threadedFunction() | |
| { | |
| while (isThreadRunning()) | |
| { | |
| if (listener != NULL) | |
| { | |
| char buffer[10]; | |
| if (fgets(buffer, 10 , stdin) != NULL) | |
| { | |
| SSHKeyListenerEventData eventData(buffer[0]); | |
| listener->onCharacterReceived(eventData); | |
| } | |
| } | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment