alt+ 0176

Oct 2, 2017 at 6:06am
when i use getch() ,i can not input alt+0176 and stuff like that.But i can do it with cin>>something...i do believe facebook or any game still accept alt+0176 (symbol like this °) eventhough that is password

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
using namespace std;

#include<conio.h>
int main() {

char a;
bool b=true;

while(b)
{
	cout<<getch();// can not input alt+0176
}
}
Oct 2, 2017 at 9:48am
Use std::cin.get

For example:

1
2
3
char c;
std::cin.get(c);
std::cout << "Got \'" << c << "\'";


Produces:
º
Got 'º'

on my system
Oct 3, 2017 at 3:07pm
don't get me wrong ... the reason i use getch() because it can hide the character so that i can use it for my password
Oct 3, 2017 at 8:51pm
neither conio.h nor getch() are part of C++ (or C), so we are left to guess what you're programming for. I'll try to guess.

Since Linux (and other Unix systems) define their getch() in curses.h, this must be MS-DOS (where it is defined in conio.h) or Windows (which mantains a conio.h for backwards compat with ancient source code)

Guessing this is for Windows, MSDN page for getch() says nothing about how this function deals with the Alt-code input. I am guessing since it predates Windows, it may simply not support it.

If that guess is right, try a WinAPI system call instead of MS-DOS:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <windows.h>
int main() {
	HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
	while (true) {
		DWORD events = 1;
		INPUT_RECORD buffer;
		ReadConsoleInput(handle, &buffer, 1, &events);
// this will trigger on key-up events for regular keys and also on the key-up of the alt 
// after entring a Windows Alt-code
		if (!buffer.Event.KeyEvent.bKeyDown
			&& !(buffer.Event.KeyEvent.dwControlKeyState & RIGHT_ALT_PRESSED)
			&& !(buffer.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED))
		{
			std::wcout << buffer.Event.KeyEvent.uChar.UnicodeChar << '\n';
		}
	}
}
Oct 5, 2017 at 7:35am
your code doesnt work...i use win 7 32 bit dev-c++
Oct 5, 2017 at 1:38pm
So my guess was close, but not quite right (I assumed Visual Studio, which is where that demo was tested). It really helps to mention the environment when using non-standard features to find people familiar with them.
Topic archived. No new replies allowed.