getch

Problem with kbhit()[and getch()] for Linux

穿精又带淫゛_ 提交于 2019-11-27 03:42:02
问题 while(ch != 'q') { printf("looping\n"); sleep(1); if(kbhit()) { ch = readch(); printf("you hit %c\n",ch); } } This code gives me a blocking getch() like functionality. I am trying to use this code to capture up down arrow keys. Added: Trying to capture key codes of up arrow gives me 3 chars 27, 91 and 65. Using if/else I am trying pattern matching but I only get 2 chars. Next one is captured when next key is pressed. I want to capture full words using getchar() while always looking for

C exit from infinite loop on keypress

徘徊边缘 提交于 2019-11-27 03:24:24
问题 How can I exit from an infinite loop, when a key is pressed? Currently I'm using getch, but it will start blocking my loop as soon, as there is no more input to read. 回答1: I would suggest that you go throgh this article. Non-blocking user input in loop without ncurses. 回答2: If you are using getch() from conio.h anyway, try to use kbhit() instead. Note that both getch() and kbhit() - conio.h , in fact - are not standard C. 回答3: The function kbhit() from conio.h returns non-zero value if any

getch and putchar not working without return

本小妞迷上赌 提交于 2019-11-26 21:58:09
问题 I have been trying to get getch to work in another program with no success. So I have made the most basic program I can using getch the way I want it to work in the main program. I have researched the need for noecho , cbreak , initscr and nodelay , I have also tried using newscr() but to no success. The problem I am having is that the chars aren't being printed to the screen till I hit "enter", when they should be put to the screen every loop. Why is this happening? Also the cursor doesn't

Non-blocking getch(), ncurses

≡放荡痞女 提交于 2019-11-26 19:59:17
问题 I'm having some problems getting ncurses' getch() to block. Default operation seems to be non-blocking (or have I missed some initialization)? I would like it to work like getch() in Windows. I have tried various versions of timeout(3000000); nocbreak(); cbreak(); noraw(); etc... (not all at the same time). I would prefer to not (explicitly) use any WINDOW , if possible. A while loop around getch(), checking for a specific return value is OK too. 回答1: The curses library is a package deal. You

How to have password echoed as asterisks

孤街醉人 提交于 2019-11-26 19:08:33
I am trying to figure out how to prompt for a password, and have the users input echoed back as asterisks ( ******** ) So recently, I took on the project of creating a remote server that could be connected to using the socket module in Python. It's not yet done, as I am in the process of making the console used to connect to the server. I am trying make a login window where a user is prompted to enter their Username and Password, although when the password is entered I am looking for asterisks to be printed, like common password entry (i.e. - Sekr3t is echo'd as: * * * * * *). After days of

How to get a single character without pressing enter?

二次信任 提交于 2019-11-26 17:31:39
How can I get a single keyboard character from the terminal with Ruby without pressing enter? I tried Curses::getch , but that didn't really work for me. http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2999 #!/usr/bin/ruby begin system("stty raw -echo") str = STDIN.getc ensure system("stty -raw echo") end p str.chr (Tested on my OS X system, may not be portable to all Ruby platforms). See http://www.rubyquiz.com/quiz5.html for some additional suggestions, including for Windows. Since ruby 2.0.0, there is a 'io/console' in the stdlib with this feature require 'io/console' STDIN

How to run program whilst listening for user input in C?

 ̄綄美尐妖づ 提交于 2019-11-26 17:07:41
问题 I'm trying to make a game that continues running until a key is pressed and then it should take that key in and do something with it then continue running as per normal. How do I do this? I'm on MAC so even though I've come across a windows library called conio.h which can handle this using kbhit() and getch(), I can't get it working for me... // // main.c // conioTesting // // #include <stdio.h> #include "myconio_mac.h" int main(int argc, const char * argv[]) { int counter = 0; while

Equivalent to Windows getch() for Mac/Linux crashes

不问归期 提交于 2019-11-26 16:53:50
问题 I am using getch() and my app crashes instantly. Including when doing: int main() { getch(); } I can't find the link but supposedly the problem is that it needs to turn off buffering or something strange along those lines, and I still want cout to work along with cross platform code. I was told to use std::cin.get() , but I'd like the app to quit when a key is pressed, not when the user typed in a letter or number then press enter to quit. Is there any function for this? The code must work

Python method for reading keypress?

女生的网名这么多〃 提交于 2019-11-26 15:21:43
I'm new to Python, and I just made a game and a menu in Python. Question is, that using (raw_)input() requires me to press enter after every keypress, I'd like to make it so that pressing down-arrow will instantly select the next menu item, or move down in the game. At the moment, it requires me to like type "down" and then hit enter. I also did quite a lot of research, but I would prefer not to download huge modules (e.g. pygame) just to achieve a single keyDown() method. So are there any easier ways, which I just couldn't find? Edit: Just found out that msvcrt.getch() would do the trick. It

getch and arrow codes

耗尽温柔 提交于 2019-11-26 11:47:47
I'm writing a programm that's using getch() to scan for arrow keys. My code so far is: switch(getch()) { case 65: // key up break; case 66: // key down break; case 67: // key right break; case 68: // key left break; } Problem is that when I press 'A' , 'B' , 'C' or 'D' the code will also executed, because 65 is the decimal code for 'A' , etc... Is there a way to check for an arrow key without call others? Thanks! qwertz By pressing one arrow key getch will push three values into the buffer: '\033' '[' 'A' , 'B' , 'C' or 'D' So the code will be something like this: if (getch() == '\033') { //