Thread: Remote keyboard
View Single Post
Old 05-09-2014, 12:32 AM   #1
0x5e
Junior Member
0x5e began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Apr 2014
Device: kindle 4 black
Question Remote keyboard

Sorry for my poor English.
Although I have a holder to hold my k4, I still have to put my hand on page down button,which makes me unconfortable.So I have an idea:How about using mobile phone to control k4 keyborad?


Code:
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <linux/input.h>
#include <fcntl.h>

//#include "input.h"

#define EV_NONE 0
#define EV_PRESS 1

void put_kbd(int fd,unsigned short key)
{
    struct input_event iev;

    iev.type = 0x04;
    iev.code = 0x04;
    iev.value= EV_PRESS;
    gettimeofday(&iev.time,NULL);
    write(fd,&iev,sizeof(iev));

    iev.type = 0x01;
    iev.code = key;
    iev.value= EV_PRESS;
    gettimeofday(&iev.time,NULL);
    write(fd,&iev,sizeof(iev));

    iev.type = 0x00;
    iev.code = 0x00;
    iev.value= EV_NONE;
    gettimeofday(&iev.time,NULL);
    write(fd,&iev,sizeof(iev));

}

void put_fw(int fd,unsigned short key)
{

    struct input_event iev;

    iev.type = 0x01;
    iev.code = key;
    iev.value= EV_PRESS;
    gettimeofday(&iev.time,NULL);
    write(fd,&iev,sizeof(iev));

    iev.value= EV_NONE;
    gettimeofday(&iev.time,NULL);
    write(fd,&iev,sizeof(iev));
}

int main(int argc, char* argv[])
{
    int fd_kbd,fd_fw;
    int key;

    if((fd_kbd = open("/dev/input/event0",O_RDWR))<-1)
    {
        printf("error open keyboard\n");
        return -1;
    }

    if( (fd_fw  = open("/dev/input/event1",O_RDWR))<-1)
    {
        printf("error open keyboard_fw\n");
        return -1;
    }

    printf("Start remote control.\n");
    while(scanf("%d",&key)!=-1 && key > 0 && key < 255)
    {
        put_fw(fd_fw,key);
        put_kbd(fd_kbd,key);
    }

    if(fd_fw>-1)
    {
        close(fd_fw);
    }

    if(fd_kbd>-1)
    {
        close(fd_kbd);
    }

    printf("Exit.\n");

    return 0;
}
using this code,I can simulate keyboard through wifi+ssh ,in computer.
but I want to use mobile phone to control k4,and I don't know how to write an android application to control k4 through ssh?
0x5e is offline   Reply With Quote