C++ :: Detect Arrow Key Press For Linux Only

May 13, 2012

I'm trying to implement this on ubuntu, to compile and run only under ubuntu.

I found 100s of other attempts at answering the general question of arrow key press in c++. Nothing solid.

Some recommend using the Readline for the functionality I am trying to implement, but I need to stay clear of GNU licences if I can for this project. And some tips only work on projects for windows machines... for example the conio library.

For linux there may be the option of using the ncurses library which I will take a look at, but I am stubborn and want to implement this myself. It should be an easy straight forward thing to do, which is why I am a bit frustrated at the moment.

Here is my test code so far.

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
using namespace std;
int main(void) {
char a;
stringstream ss;
string s;

[Code] ....

So! This works... 80% of the problem is solved. If you compile this, g++ under linux, ubuntu in my case, and run. Each keystroke reveals the correct key numbers.

q=113
w=119

when I click on the up key I get,

up = 279165

I thought, I can use this number is a if(int == '279165') to detect the up key.

I was not so lucky... this int is not behaving like an int!

So I modified the code to see it I could carry out an int operation on this number.

I added a 100000 to int i.

cout<< i + 100000;

Code:
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
using namespace std;
int main(void) {
char a;
stringstream ss;
string s;

[Code] .....

Compiling and running this, and pressing the UP key gives the following number.

100027100091100065

Some some sort of array, something like, [27][91][65].

I tried all ways to access these individual numbers, actually the third one for comparison purposes, but no luck.

For completeness sake I list the other arrows.

UP = [27][91][65]
DOWN = [27][91][66]
LEFT = [27][91][68]
RIGHT = [27][91][67]

A little further digging shows that these numbers are derived from the representation of a "multi-char" constant, the data type given when pressing special characters...

Now here is the main problem I have, I can find ANY decent documentation on how to handle and play with "multi-char" .

View 4 Replies


ADVERTISEMENT

C Sharp :: How To Detect Whenever Down Arrow Key Is Pressed

Jun 3, 2012

So, I've been working on a project recently, and the only thing remaining to do is a detector to whenever down arrow key is pressed. The down arrow key can only trigger when a certain check box is checked and this will have to work with a timer either. The problem is that how to make the down arrow key press detector(I've got the check box and timer ready tho).

View 10 Replies View Related

C :: Detect CPU Power Button Press Event In Console Application

Feb 5, 2015

I am using Windows 7 32bit OS and want to detect the CPU power button press event in my console application developing in C language.

I configured the power button setting to "Do Nothing" which is in "Choose what the power button does" options in Control Panel->Hardware and Sound->Power Options. So now i want to detect this power button press event and do some processing in my application then i will initate shut down from application itself. Looking for windows API details which will detect the power button press event.

View 2 Replies View Related

C++ :: Dot Operator Versus Arrow

Jun 26, 2014

I understand that the dot operator is:

Code: a.b "a"

is the actual object (not a memory location) and "b" is the member. I also understand the arrow to mean:

Code: a->b "a"

is a pointer to a struct and "b" is it's member so "a" is dereferenced then "b" is given.

Here is where I get a little confused. I have a class:

exampleclass.h
Code:
#ifndef EXAMPLECLASS_H_INCLUDED
#define EXAMPLECLASS_H_INCLUDED
class exampleclass{

[Code].....

Also if ec1 had a public variable and I wanted to access it would it be referenced the same way as the method I call in ec1?

View 4 Replies View Related

C :: How To Make A Menu That Uses Arrow Keys

Feb 12, 2015

My program uses a menu that easily facilitates a person to navigate trough out it but im stuck on a part and I cant go to menu3 with the arrows (only use c code not c++)

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
void sleep(long int interval) {
for(int i=0;i<interval*1000;i++);}

[Code]...

View 6 Replies View Related

C :: How To Create Menu Selection With Arrow Key

Jun 22, 2014

I'm looking for an example of menu selection with arrow key i'dont know how to create one o think i should use CODE ASCI but what method I should follow

View 1 Replies View Related

C++ :: Visual Arrow Following Motion Of Ball?

Aug 25, 2013

I have created plane as floor and sphere as ball. I used physics equations to it and ball falls under gravity. Now i want to attach visual arrow to this ball which moves with it according to velocity direction. If ball bounces then direction of velocity is changed so does arrow.

View 1 Replies View Related

C# :: TextBox Navigation Using Arrow Keys

Mar 2, 2014

So I have assigned this method to each TextBox. It works fine pressing the left arrow and right arrow, but for some reason will not work using the up and down arrows. I have tested the string, using MessageBox and it is correct...the loop even proves it finds a matching TextBox. It is correct as in it displays the TextBox name it should be selecting but doesn't. I have no clue! Now the first select method is the one I want to use, I used the loop to check to see if it was even finding a match. It does find it but doesn't select it. The naming convention for my text boxes is r1c1 where the first number indicates the row and the second number is the column. There are 9 rows and 9 columns. This SHOULD be working but for whatever reason it is not. I've even put a message box inside the if statement for the up and down keypress check and it pops up when i press up or down.

private void Navigate(object sender, KeyEventArgs e) {
TextBox input = (TextBox)sender;
string nextBox = input.Name.ToString();
if (e.KeyCode == Keys.Left) {
if (int.Parse(nextBox.Substring(1, 1)) > 1 && int.Parse(nextBox.Substring(3, 1)) == 1)

[Code] ....

View 7 Replies View Related

C :: Double Use Of Arrow Operator With Pointer / Function

Feb 24, 2015

I have recently come across a function call that I do not understand. It uses the arrow operator for a function call, twice, and I don't understand.

Code:

static inline void b43_write32(struct b43_wldev *dev, u16 offset, u32 value)
{
dev->dev->write32(dev->dev, offset, value);
}

I see that the function itself does not return anything but calls another function. The main difficulty I have is with the "dev->dev->" operator, where dev, I expect is a pointer to a structure.

View 8 Replies View Related

C++ :: Array Char Rotation And Arrow Key Usage

Apr 27, 2013

I am doing a project for a class which involves making a game where there is an arrray that holds a player (you) and a zombie (comp). The player is suppose to be able to turn clockwise or counter clockwise, move forward, and backward and shoot. Im having trouble trying to rotate the char in an array. I am also trying to switch from using the W,S,D,A to the arrow keys but doesnt seem to work.

#include <iostream>
#include <windows.h>
#include "color.h"
using namespace std;
using namespace Petter;
const int COL = 15;
void initBoard(char[][COL], int, int);

[Code] ....

View 5 Replies View Related

C++ :: Print In Asterisks Oval / Arrow And Diamond Using For Loop And If Statements

Jan 15, 2015

#include <iostream>
using namespace std;
int main(){
return 0;
}

this is my main functions. I have problem making a program that prints in asterisks an oval, arrow and a diamond using for loop and if statements.

View 1 Replies View Related

C++ :: When Press The Up Key It Will Not Display Anything

Mar 26, 2014

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <ctype.h>

[Code]....

When I press the up key it will not display anything.

View 2 Replies View Related

C++ :: SDL Key Press Delay

Jan 3, 2014

When you press a key it automatically delays a bit then starts repeating without delay.

The second key pressed action comes with a delay and i want it to start repeating without delay. And could not find anything useful.

I might not be able to tell what i want exactly. Ok press simply a key and don't release it in a text editor. You will realize a delay at second character showing up.

View 7 Replies View Related

C/C++ :: How To Use Press Any Key To Continue

Mar 28, 2015

I already tried getchar(); but it doesn't worked the program skips this command

View 2 Replies View Related

C++ :: Stopping Codes With A Key Press

Feb 25, 2013

I have a program that I made, which does a list of stuff, then checks if a key is pressed, and if it's pressed, stop the looping.

The problem is, it checks if the key is pressed once a loop, which means that if the list has delays, you have to hold the button down for a while (depending on the list).

Here's an example:
Move mouse;
Pause program for 2 seconds;
Move mouse;
Pause program for 2 seconds;
Check if key is pressed;

What ways can I fix this problem?

View 1 Replies View Related

C/C++ :: Program Skips To Press Any Key

Jun 8, 2014

I am altering this program to include some alterations for a class. When I run it with start without debugging, it just skips to press any key to continue. It will not display the cout << "Volume of box1 = " <<boxVolume1.

#include "stdafx.h"
#include <iostream>
using std::cout;
using std::endl;
class CBox {
public:
double m_Length;
double m_Width;

[Code] .....

View 1 Replies View Related

C# :: How To Jump From One TextBox To Next When Press Enter Key

Apr 13, 2014

How can i jump from textBox to next texBox when i press enterKey in c# , what i the event for that .....

View 2 Replies View Related

C# :: How To Add Keyboard And Button Press To A Program

Apr 13, 2014

I have a problem where I need to add the ability to input numbers into a calculator program through either a form button press or keyboard press. I have the button press working fine though I can't seem to get the program to start with the cursor active in the textbox for keyboard input. I've use this.ActiveControl = result; "result" being the textbox. Though the issue here is the program starts off with the cursor active but only for the first instance of keyboard inputs.

Perhaps its the way I wrote the program but is there a way I can achieve this? I found a way to write this calc by having a single event for all button presses, opposed from an event for 1-9. Not sure if this is a good approach but here is some of the code.

private double num = 0;
private string calculate;
bool pressed = false;
private void button_Click(object sender, EventArgs e) {
if ((result.Text == "0")||(pressed == true)) {

[Code] ....

View 1 Replies View Related

C++ :: Simple Calculator - Press A Key To Continue

Apr 20, 2015

My problem is , i want to make a simple calculator , in the console i want afterall the user to choose what type of operation he want pressing a key like i mentioned in the title the keys would be F1,F2,F3 , i'm not finding in the internet the code to the detection of a press key like what i want.

Code:
#include <iostream>
using namespace std;
int F1 (int x, int y) {
cout << "Enter a number: " << endl;
cin >> x;

[Code] ....

View 7 Replies View Related

C :: Make A Program Press A Key As If It Had Been Pressed On Keyboard?

Dec 28, 2013

I would like to know how to press a key as if it had been pressed on the keyboard in a program. I would also like to know how to read input from a xbox 360 controller. I want to know how to do this so that I can add joystick support to a few mmos that I play that do not already have it.

BTW I am using C 99

View 2 Replies View Related

C++ :: User Press Space To See Next Line Of Output?

Jun 10, 2013

I have been trying to make a small program that I will be using in a larger program that will make the user press space to see the next line of output.

Not exactly sure what I'm doing wrong, but I'm pretty sure that I need to put the space that the user would enter into an output file, and the read the input file

It runs, but it doesn't allow me press space before showing the next line.

I added a getline(cin, charVar) before, but I got a whole bunch of errors.

#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
#include <fstream>
using namespace std;
// function for dialouge

[Code] ....

View 4 Replies View Related

C++ :: No Input - Forcing User To Press Enter Twice

Aug 25, 2013

When the user gives no input, they have to press enter twice before "Done." is printed.

cout << "What do you want the name of your page to be? ";
std::getline(cin, pageTitle);
if (cin.get() == '
')
pageTitle = "Welcome to Website.";
cout << "Done.
";

Is there a way to print "Done." after pressing enter once?

View 2 Replies View Related

C++ :: System (PAUSE) Without Message Or Button Press

Nov 7, 2013

I would like to have my program pause at a certain screen but not to have the "Press any key to continue..." message or the press of a button. In my program, the code looks similar to this:

for(;;)
{
cout
cin
cout
cin
...
//

here, I want to have a pause to view what the for loop has come up with but to not have a message display or a button press needed. At the end of the loop, I want it to pause before looping again. IS this possible?

If so, how can I implement it into my program?

View 1 Replies View Related

Visual C++ :: Does Not Contain Debug Information - Press OK To Continue

Sep 18, 2012

i changed my code from release to debug mode. when i try to debug it shows a dialog box that '... does not contain debug information press ok to continue"..

View 8 Replies View Related

C++ :: Program To Input Password - Press Enter Only Once?

Jan 16, 2013

Code:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main() {
clrscr();
int i=0,flag=1;
cout<<"Enter the password.";

[Code] ....

When I input the password, the Backspace and the Enter keys are not working as they should. Also, I want to know if I can press enter only once to input the password, not twice.

Compiler is Turbo C++ 3.0 on Windows 7.

View 1 Replies View Related

C++ :: Program To Stay Open Until Press Enter Even After Whole Output

Oct 10, 2013

My program closes after the out even though i've used cin.get():

I want the program to stay open at least until you press enter, even after the whole output.

Code:
#include <iostream>#include <string>
int main()
{
std::cout << "Please enter your name";
std::string name;
std::cin>> name;
// build the message that we intend to write

[Code] .....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved