Hello,
I was wondering if there was a way (in c++) to move the cursor when pressing the arrow keys instead of getting ^[[C resp. ^[[D (left resp. right arrow) in the cin input - I am using linux. I guess this behavior is controlled by the terminal, therefore not modifiable, or does anyone have an idea? I thought of getting one character at the time, check it against the arrow codes, and in case print the ANSI codes for moving the cursor, but the problem is that getting one character at the time also does not seem to be easy...
Thanks for any inputs!
Cheers,
Sandro
2 7211
Hello,
I was wondering if there was a way (in c++) to move the cursor when pressing the arrow keys instead of getting ^[[C resp. ^[[D (left resp. right arrow) in the cin input - I am using linux. I guess this behavior is controlled by the terminal, therefore not modifiable, or does anyone have an idea? I thought of getting one character at the time, check it against the arrow codes, and in case print the ANSI codes for moving the cursor, but the problem is that getting one character at the time also does not seem to be easy...
Thanks for any inputs!
Cheers,
Sandro
Well, you have to do two things.
1. disable terminal echo using the termio library. This involves creating a struct and turning the ECHO flag off. Sorry I don't have sample code, just look up "disable terminal echo"
2. Once you have disable it, you can only read a char at a time in and you have to output it yourself if you want it to echo to the terminal. This allows you to move the cursor with the arrow keys.
Max
Well, you have to do two things.
1. disable terminal echo using the termio library. This involves creating a struct and turning the ECHO flag off. Sorry I don't have sample code, just look up "disable terminal echo"
2. Once you have disable it, you can only read a char at a time in and you have to output it yourself if you want it to echo to the terminal. This allows you to move the cursor with the arrow keys.
Max
Thanks for your answer, I googled a bit and found a code that does what I need based on the termio library. In case anyone else has the same problem, here is the code: - #include <stdio.h>
-
#include <unistd.h>
-
#include <termios.h>
-
-
-
int getch(void)
-
{
-
int ch;
-
struct termios oldt;
-
struct termios newt;
-
tcgetattr(STDIN_FILENO, &oldt); /*store old settings */
-
newt = oldt; /* copy old settings to new settings */
-
newt.c_lflag &= ~(ICANON | ECHO); /* make one change to old settings in new settings */
-
tcsetattr(STDIN_FILENO, TCSANOW, &newt); /*apply the new settings immediatly */
-
ch = getchar(); /* standard getchar call */
-
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); /*reapply the old settings */
-
return ch; /*return received char */
-
}
-
-
-
int main()
-
{
-
char x = ' ';
-
-
printf("Press any key to continue...\n");
-
x = getch();
-
-
printf("The key you entered is: %c \n", x);
-
-
return 0;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Hung Huynh |
last post by:
Hi,
I'm trying to use either one of these methods to position the cursor in a
specific position inside a recordset, but neither one seems to work.
For example, I have 10 records in my rsData recordset, and I issue this
command
rsData.Move 5, 1 'move to #5 from beginning
|
by: mcanedo |
last post by:
Hi:
I have several text elements in a form.
Some of they are filled by the user, and then some are automatically filled
based on the user input.
Therefore I do not want the user to be able to write on the autofilled text
elements.
I have come to the idea of give those elements the event
onFocus=functiontoMovetoNextElement()
Then my...
|
by: Seash |
last post by:
Hi friends ,
here is the sample code
private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == 13) //enter
{
txtbox2.Focus();
}
|
by: gmtongar |
last post by:
Hi,
I've made a custom scrollbar which consists of three buttons and a panel. My problem is: How do I move it like a scrollbar slider? I've tried DoDragDrop, but it does not appear to be the same, all though I can move the button. I have also used the mouseMove event, so I can move the button, but it's completely out of control. Still I feel it's...
|
by: Phil Endecott |
last post by:
Dear Postgresql experts,
According to the documentation for MOVE, it returns the number of rows
that it has moved over. It seems to me that this is true for MOVE
FORWARD n, but not for MOVE RELATIVE n or MOVE ABSOLUTE n when it always
returns 1:
db=> declare c scroll cursor for select * from p;
DECLARE CURSOR
db=> move absolute -1 in c;
| |
by: Rahna |
last post by:
Hi,
I'm using the DirectSS1 Speech Control in my VB 6 application. I tried to use the WordPosition Event to move the cursor along with the speech.
the code goes like this
Private Sub DirectSS1_WordPosition(ByVal hi as long, ByVal lo as long, ByVal ByteOffset as long)
RichTextBox1.SelStart=ByteOffset/2
|
by: yan.python |
last post by:
i have a question.
when i run Interactive Interpreter in linux command promt,how can i
move the cursor.
for example,when i enter a string,i often enter the quotation mark ""
first,and the move the cursor inside the mark to enter the string,in
windows,it is ok.but when i do that in linux,pressing the "left" key
will just print "^[[D" in the...
|
by: =?Utf-8?B?cmFuZHkxMjAw?= |
last post by:
Can anyone offer pointers to articles/examples of passing a Ref Cursor
***IN*** to an Oracle stored procedure. I find tons of examples for getting a
ref cursor OUT of a stored procedure. I'm using the
Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory, NOT the ODT.NET
library (please don't ask why).
Thanks,
Randy
|
by: michels287 |
last post by:
Right now I have a touchscreen with a virual keyboard.
I would like to create arrow keys. If the user messed up the inputted text, he can move the blinking cursor left one space at a time between inputted characters to add a letter. Then a button to move the blinking cursor back to the end of the inputted text.
Private Sub Left...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |