LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 05-27-2017, 11:29 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,357

Rep: Reputation: 211Reputation: 211Reputation: 211
Plain C Programming: Capturing Key Code in the Linux Console (printf keycode)


Hello,

There is a great tool which is known as showkey.
With skowkey --scancodes, you can see absolutely all keys (even XF86 keys) of your keyboard. It does search too from all /dev/input devices such as platform, usb, ... and so on.

Showkey is here: https://kernel.googlesource.com/pub/.../src/showkey.c

If you want to find keys, you can use this code (from stackoverflow):
Code:
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    int fd;
    if(argc < 2) {
        printf("usage: %s <device>\n", argv[0]);
        return 1;
    }
    fd = open(argv[1], O_RDONLY);
    struct input_event ev;

    while (1)
    {
    read(fd, &ev, sizeof(struct input_event));

    if(ev.type == 1)
        printf("key %i state %i\n", ev.code, ev.value);

    }
}
Would you know some small size C programme, which can be well easy compiled to view keystrockes? (without too much to deps.).

Like does showkey, but like always, in a minimalist way in order to learn the basics of Linux !

Last edited by Xeratul; 05-27-2017 at 11:34 AM.
 
Old 05-27-2017, 01:24 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,414
Blog Entries: 6

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Xeratul, you have fallen into a pattern of posting threads of the recurring form, "Would anyone know a (tiny|minimalist) way of performing [enter random topic here] in C?", usually accompanied by pasted code and/or some link to an off-site page on the internet.

Whlie the subjects are obviously of passing interest to you, these posts are vague, often not having an identifiable answer, and do not rise to the standards required by the LQ guidelines, to which I now refer you.

I ask you to please refrain from such posts in the future, in the Programming forum. If you have a specific programming question, which has an answer, the Programming forum is the right place. If you have a topic of of passing or general interest which you wish to discuss, and that does not rise to the level of a programming question, then the General forum is probaby more appropriate.

If you simply wish to share your code, examples and learning experience, then again I would suggest that you make use of your blog space here on LQ.

Please help us maintain the high quality and ready accessibility of information in the Programming forum.

And please review the LQ guidelines for posting questions and discussions in future.
 
Old 05-27-2017, 02:15 PM   #3
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,357

Original Poster
Rep: Reputation: 211Reputation: 211Reputation: 211
Quote:
Originally Posted by astrogeek View Post
Xeratul, you have fallen into a pattern of posting threads of the recurring form, "Would anyone know a (tiny|minimalist) way of performing [enter random topic here] in C?", usually accompanied by pasted code and/or some link to an off-site page on the internet.

Whlie the subjects are obviously of passing interest to you, these posts are vague, often not having an identifiable answer, and do not rise to the standards required by the LQ guidelines, to which I now refer you.

I ask you to please refrain from such posts in the future, in the Programming forum. If you have a specific programming question, which has an answer, the Programming forum is the right place. If you have a topic of of passing or general interest which you wish to discuss, and that does not rise to the level of a programming question, then the General forum is probaby more appropriate.

If you simply wish to share your code, examples and learning experience, then again I would suggest that you make use of your blog space here on LQ.

Please help us maintain the high quality and ready accessibility of information in the Programming forum.

And please review the LQ guidelines for posting questions and discussions in future.
A forum for programming would be indeed better adapted.
There is stackoverflow or a plain C forum.

Let's take an example. There are many examples in C for learning
https://stackoverflow.com/questions/...n-raspberry-pi

The place of Linuxquestions is mostly for Linux, and not for only programming.
 
Old 05-27-2017, 04:00 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,414
Blog Entries: 6

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by Xeratul View Post
A forum for programming would be indeed better adapted.
...
The place of Linuxquestions is mostly for Linux, and not for only programming.
LinuxQuestions has many different forums, each with its own focus. You may find the complete list at the top of each page through the Forums link.

The place of the Programming forum is stated at the top of each page in the Programming forum:

Code:
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
And again, the LQ Rules and Site FAQ provide the clear guidelines for participation in each LQ forum. It is recommended that all LQ members review them from time to time.
 
Old 06-08-2017, 09:38 PM   #5
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 142Reputation: 142
This seems tiny already to me! Some C programs are like the size of an encyclopedia when printed out!
 
Old 06-08-2017, 09:45 PM   #6
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 142Reputation: 142
If you want small, learn Perl, C will always be wordy.
 
Old 06-09-2017, 10:43 AM   #7
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,357

Original Poster
Rep: Reputation: 211Reputation: 211Reputation: 211
Quote:
Originally Posted by Laserbeak View Post
If you want small, learn Perl, C will always be wordy.
I am a C believer, nothing can't be portability on other platforms using C.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
change the keycode of the key m4rtin Linux - Server 1 11-28-2011 02:47 PM
Is it possible to change the keycode on a key? riwaJR Linux - General 4 03-30-2009 10:03 AM
Hiding printf( C programming) outputs from console mendiratta General 3 11-20-2008 03:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 09:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration