getch

Why doesn't getch() read the last character entered?

人盡茶涼 提交于 2019-12-11 00:48:39
问题 I am writing a snake game in C using the ncurses library, where the screen updates itself every second. As those who have played the game will know, if the user enters various keys or holds down a key for long, there should be no 'buffered' key presses which get stored. In other words, if I hold down w (the up key) and stdin receives a sequence of 20 w s, and subsequently enter a d (the right key), I expect the snake to immediately move to the right, and ignore the buffered w s. I am trying

Why getch() is not working in Visual Studio 2008?

给你一囗甜甜゛ 提交于 2019-12-10 23:39:48
问题 Below code works in DevC++ with MinGW works flawlessly but Visual Studio 2008 spits this: error C3861: 'getch': identifier not found . What can I do to accept getch() if this is not possible is there an alternative to getch() that I can use to pause the screen? Code: #include <stdio.h> #include <conio.h> int main(void){ char str[] = "This is the end"; printf("%s\n", str); getch(); //I tried getchar() also still does not work return 0; } 回答1: use _getch() e.g. #define getch() _getch() sample

Python input single character without enter

落爺英雄遲暮 提交于 2019-12-10 15:29:13
问题 What I am trying to do is make a simple pi memorization game in Python. What I need is a way to get input from the user without having to press 'enter' after every character. It sounds like I need something like getch, but I can't get it to work. I got a getch-like function from here: https://gist.github.com/chao787/2652257#file-getch-py. I don't really understand anything that's in there. When I do ' x = getch.getch() ' it says " AttributeError: '_Getch' object has no attribute 'getch' ". It

How to detect when the delete key is pressed on the keyboard?

夙愿已清 提交于 2019-12-08 11:42:30
问题 I want that when the Del key is pressed a certain function is called. How can I achieve that using getch() if possible or otherwise some nested getch() calls? 回答1: The function _getch() returns an "escaped" value for cursor and page control keys. For the keypad and the function keys, that is 0 followed by the key code, for other keys it is 224 followed by the key code. #include <stdio.h> #include <conio.h> #define ESC 27 #define ESC1 0 #define ESC2 224 int main() { int d=-1, e=-1; printf(

curses library: why does getch() clear my screen?

寵の児 提交于 2019-12-07 00:59:21
问题 I'm trying to learn the curses library (pdcurses, as I'm in Windows OS), with C++. I have a program that displays 3 windows, then a while loop to do some processing based in key presses captured by getch(). The loop gets exited when the F1 key is pressed. However, despite refreshing all three windows with wrefresh(), nothing appears before I enter my first key press. Without the while loop, everything is displayed fine. I've made numerous tests and it's like the first call to getch() will

Check for extra characters in Linux terminal buffer

♀尐吖头ヾ 提交于 2019-12-05 07:22:46
问题 I try to implement getch() function in Python, which should also return list of chars for special keys like F1-F12 and arrow keys. These special keys generate several chars in a sequence. Therefore getch() reads one char in blocking mode and then should check if there are extra chars in input buffer to fetch them too. I am using ioctl call together with termios.FIONREAD to get the number of bytes in the input buffer. It catches non-special key presses stacked in buffer, but misses extra

curses library: why does getch() clear my screen?

我们两清 提交于 2019-12-05 06:50:57
I'm trying to learn the curses library (pdcurses, as I'm in Windows OS), with C++. I have a program that displays 3 windows, then a while loop to do some processing based in key presses captured by getch(). The loop gets exited when the F1 key is pressed. However, despite refreshing all three windows with wrefresh(), nothing appears before I enter my first key press. Without the while loop, everything is displayed fine. I've made numerous tests and it's like the first call to getch() will completely clear the screen, but not the subsequent ones. My question is: what did I miss? At first, I was

PyCharm: msvcrt.kbhit() and msvcrt.getch() not working?

亡梦爱人 提交于 2019-12-04 02:50:37
问题 I've tried to read one char from the console in PyCharm (without pressing enter), but to no avail. The functions msvcrt.getch() stops the code, but does not react to key presses (even enter), and msvcrt.kbhit() always returns 0. For example this code prints nothing: import msvcrt while 1: if msvcrt.kbhit(): print 'reading' print 'done' I am using Windows 7, PyCharm 3.4 (the same heppens in idle). What is wrong? Is there any other way to just read input without enter? 回答1: It's possible in a

PyCharm: msvcrt.kbhit() and msvcrt.getch() not working?

非 Y 不嫁゛ 提交于 2019-12-01 15:56:31
I've tried to read one char from the console in PyCharm (without pressing enter), but to no avail. The functions msvcrt.getch() stops the code, but does not react to key presses (even enter), and msvcrt.kbhit() always returns 0. For example this code prints nothing: import msvcrt while 1: if msvcrt.kbhit(): print 'reading' print 'done' I am using Windows 7, PyCharm 3.4 (the same heppens in idle). What is wrong? Is there any other way to just read input without enter? It's possible in a special mode of the Run window. Check the Emulate terminal in output console setting checkbox in Run/Debug

Reading a single character (getch style) in Python is not working in Unix

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 17:57:41
问题 Any time I use the recipe at http://code.activestate.com/recipes/134892/ I can't seem to get it working. It always throws the following error: Traceback (most recent call last): ... old_settings = termios.tcgetattr(fd) termios.error: (22, 'Invalid argument) My best thought is that it is because I'm running it in Eclipse so termios is throwing a fit about the file descriptor. 回答1: This is working on Ubuntu 8.04.1 , Python 2.5.2, i get no such error. May be you should try it from command line,