473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Console and keys

Hello!
How can I get key code in console program? Eg. When I press ENTER then
he show me code 13, when CTRL then code of CTRL key, ALT...

In C# Helpis only one example, but they not detect CTRL, ALT, ESC key press.

--
Best regards, gregory
Nov 16 '05 #1
1 2016
Gregory,

This is a little tricky. First, you have to create your own input
buffer for the console through a call to CreateConsoleScreenBuffer. Once
you have that, you have to set it to the active screen buffer by making a
call to SetConsoleActiveScreenBuffer. After that, you have to call
SetConsoleMode with a parameter of ENABLE_ECHO_INPUT, so that the characters
are written to the buffer one by one, and not when a line is input.
Finally, to get the input, you would have to call ReadConsole.

All of these are API functions which you would have to declare and call
through the P/Invoke layer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"rozrabiak" <br**@maila.pl> wrote in message
news:ck**********@news.onet.pl...
Hello!
How can I get key code in console program? Eg. When I press ENTER then he
show me code 13, when CTRL then code of CTRL key, ALT...

In C# Helpis only one example, but they not detect CTRL, ALT, ESC key
press.

--
Best regards, gregory

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method:...
1
by: Ulrich Kotzolt | last post by:
I use to get the function keys that were pressed in an console application cause this application should also be used over a telnet server. Does someone know how to get the keys. Tanks for your...
4
by: Chris Williams | last post by:
Hi... I'm trying to find some code samples that will show me how to capture non-character keypresses in a console app. I've tried the standard stuff, such as console.read and console.readline,...
1
by: Doug Perkes | last post by:
I have a legacy console application that I need to control with a c# desktop application. The main functionality i need is the following: Send strings Read strings at specific locations Send...
2
by: Tiësto | last post by:
Sometimes I have a string variable with many escaped characters. And when I write ?MyString in the Immediate window, the output is done with the \n \t and similar characteres. Is there any...
12
by: Jarod_24 | last post by:
I got a project called "Forms" that hold some forms and stuff in my solution. A argument at startup defines wether to use a From or Console. My plan was to create a myConsole class that would...
5
by: Hooyoo | last post by:
Hi, here. I write following codes: string password = Console.ReadLine(); I want users enter their passwords, but readline will show content of password when entering, so is there any way to...
3
by: Marco Shaw | last post by:
C# novice... Can I create a console application (think the Pine email reader or even 'edit' in DOS) where I can use my up/down/side arrows to move around the app? I'd want something with a...
4
by: Mo | last post by:
Hi, I am writing a console application to send a key sequence to an old clunky application on a regular interval using the windows scheduler. I can get it to work if it is a windows form...
4
by: =?Utf-8?B?QWxleGFuZGVy?= | last post by:
Hi! I am new to C#. I read two C# books in the last two days which only covered the basics. And now I am on my third day. The books were really bad, because they did not cover windows applications,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.