getch

Python Windows `msvcrt.getch()` only detects every 3rd keypress?

独自空忆成欢 提交于 2019-12-17 19:25:14
问题 My code is below: import msvcrt while True: if msvcrt.getch() == 'q': print "Q was pressed" elif msvcrt.getch() == 'x': sys.exit() else: print "Key Pressed:" + str(msvcrt.getch() This code is based on this question; I was using it to acquaint myself with getch . I've noticed that it takes 3 pressing the key 3 times to output the text once. Why is this? I'm trying to use it as an event loop, and that's too much of a lag... Even if I type 3 different keys, it only outputs the 3rd keypress. How

How to use kbhit and getch (C programming) [closed]

谁都会走 提交于 2019-12-17 09:59:50
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I'm trying to create a function that will printf a certain string if the user presses any button on the keyboard EXCEPT for capital P , if the user presses P then it will break the loop. However I don't think I'm using _kbhit and _getch properly. I use the number 80 because that is the ASCII symbol for 80...

Python method for reading keypress?

对着背影说爱祢 提交于 2019-12-17 03:07:45
问题 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

Problem with an expect script

心不动则不痛 提交于 2019-12-13 01:28:41
问题 I'm trying to create a script to update a password in a non-interactive way. It's working on my laptop but fails on my server. Both are running the same configuration, using Etch. This is the script: #!/usr/bin/expect -f # Change user passwd set timeout 30 strace 4 set password [lindex $argv 1] set old_password [lindex $argv 2] spawn passwd [lindex $argv 0] sleep 1 expect "(current) UNIX password: $" send "$old_password\r" expect "Enter new UNIX password: $" send "$password\r" expect "Retype

Get line feed with getch in Ruby

拜拜、爱过 提交于 2019-12-12 05:03:14
问题 I have the following code: require 'io/console' loop do character = STDIN.getch break if character == "\n" print "*" end The code is working, but I have to press the Enter key then another key to break the loop. Why? I have this issue only with the line feed. 来源: https://stackoverflow.com/questions/47232924/get-line-feed-with-getch-in-ruby

How to use Escape Key to end a Loop in C

99封情书 提交于 2019-12-12 04:53:50
问题 I just want to end a do while loop in C like this: #include <stdio.h> #include <stdlib.h> main() { char exit; do{ printf("PLEASE INSERT OPTION:"); exit = getchar(); }while(exit != '\027'); }//main I think it is kind of this way. 回答1: 27 is the decimal ASCII value for Escape, but you use an octal character code. You should say 27 , or '\033' (or '\x1b' for hex which is more common). This might be the problem, assuming your terminal lets through the Escape character. Sometimes they're used for

Xcode Swift Command Line Tool reads 1 char from keyboard without echo or need to press return [closed]

爱⌒轻易说出口 提交于 2019-12-11 11:03:38
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I need a function, like the old "getch()", in Objective C or Swift to read one single character from the keyboard without echo and without the nedd to press return after the character has been typed to make the function continue. This is, I know, only interesting when programming

getch(); does not pause the loop

喜你入骨 提交于 2019-12-11 09:41:24
问题 I have this piece of code for instance: while(true){ printf("looping"); getch(); } Instead of waiting for user input on each loop, the loop just continues without me; printing loop loop loop until I close the program. Is there a better way to read a single character ? All i really want to do is to have the user input a 'y' or a 'n' 回答1: Just use fgetc. I assume you're using this to break out of the loop, so to update your example: #include <stdio.h> char iput; while(true){ printf("looping");

msvcrt.getch() detects space every time

杀马特。学长 韩版系。学妹 提交于 2019-12-11 05:24:28
问题 Im writting a simple python code that should detect the my keystrokes but for some reason in detects space after everysingle keystroke. The code: import msvcrt print("press 'escape' to quit...") text="" while 1: char = msvcrt.getch() print(ord(char)) Sample run: Input: aaaaa Output: 97 0 97 0 97 0 97 0 97 0 回答1: It's not detecting space. Space is 32 , not 0 . What's happening is that you're using a wide-character terminal, but reading it as bytes, so you're seeing the UTF-16-LE bytes. In UTF

Strange behavior with function parameters and getch()

时光毁灭记忆、已成空白 提交于 2019-12-11 04:28:50
问题 I am running in to some strange behavior with calling functions with parameters that contain getch(). Take the following code for example: _Bool IsKeyDown(char c) { if(!kbhit()) return 0; char ch1 = getch(); printf("%c\n", c); return 0; } /* * */ int main(int argc, char** argv) { while(1) { IsKeyDown('a'); IsKeyDown('b'); Sleep(100); } return (EXIT_SUCCESS); } When a key is pressed with this code, no matter what, it will always print 'a', which is the parameter of the first function. The