Skip to content

Instantly share code, notes, and snippets.

@jvcleave
Last active December 17, 2015 11:38
Show Gist options
  • Select an option

  • Save jvcleave/5603227 to your computer and use it in GitHub Desktop.

Select an option

Save jvcleave/5603227 to your computer and use it in GitHub Desktop.
get keypress from SSH terminal in OF/RPi app
#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