LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-02-2018, 12:55 PM   #1
jpsoccer435
LQ Newbie
 
Registered: Oct 2018
Posts: 2

Rep: Reputation: Disabled
Recognizing keyboard strokes after programming


I am developing a C program in Linux that enters 0 for a certain amount of time and 1's when the space key is pressed. It should run for a maximum amount associated with command-line arguments.

I got the part on how to make it print 0 for the time requested by the user but can't figure out how to print 1's instead of 0 when the space key is pressed. If I do a scan or get function it stops the program because its waiting for a user input and that is not what i want.

ex:
0
0
0
0 ___> user holds space key
1
1
1
1 ____> user lets go of space key
0
0
 
Old 10-02-2018, 01:09 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Welcome to LQ!

No one can provide any helpful response from the information you have posted.

The best way to get help is to reduce the problem to a simplest case which clearly demonstrates what you are trying to accomplish, and fails to work in the way expected. Very often you will solve the problem yourself while doing that, and the simple example will allow others to quickly understand the question and provide helpful suggestions.

Please review the Site FAQ for guidance in asking well formed questions.
 
Old 10-02-2018, 01:13 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
This thread covers a few options:

https://stackoverflow.com/q/20349585/240515
 
Old 10-02-2018, 01:26 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
check this, making your other one as a dup
https://www.linuxquestions.org/quest...8/#post5910250
 
Old 10-02-2018, 10:22 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
You could start with ncurses using functions noecho, cbreak, nodelay and getch.
 
  


Reply



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
Recognizing keyboard strokes after programming. jpsoccer435 Linux - General 2 10-02-2018 02:11 PM
Modifying keyboard for extra key strokes. Bob Fletcher Linux - Desktop 11 09-02-2017 02:48 AM
[SOLVED] Injecting key strokes to simulate a keyboard theosys Programming 9 11-03-2016 01:17 PM
Reading keyboard strokes from different windows through C Aquarius_Girl Linux - General 1 05-05-2010 09:29 AM
USB keyboard - Capture key strokes/input v333k Linux - Software 2 10-19-2009 01:44 PM

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

All times are GMT -5. The time now is 01:30 PM.

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
Open Source Consulting | Domain Registration