Make input element (type=”text”) handle multiple lines of text

You need to use an HTML <textarea> element. From MDN: <textarea> The HTML <textarea> element represents a multi-line plain-text editing control. Using <input> for multiline text is not possible natively and, if hacked, would be invalid HTML. HTML5 spec: 4.10.5.1.2 Text (type=text) state and Search state (type=search) The input element represents a one line plain … Read more

Python: How to get input from console while an infinite loop is running?

Another way to do it involves threads. import threading # define a thread which takes input class InputThread(threading.Thread): def __init__(self): super(InputThread, self).__init__() self.daemon = True self.last_user_input = None def run(self): while True: self.last_user_input = input(‘input something: ‘) # do something based on the user input here # alternatively, let main do something with # self.last_user_input … Read more

Why doesn’t pressing enter return ‘\n’ to getch()?

Use ‘\r’ and terminate your string with ‘\0’. Additionally, you might try to use getche() to give a visual echo to the user and do some other general corrections: #include <stdio.h> #include <conio.h> #define MAX_NAME_LENGTH 20 int main() { char ch, name[MAX_NAME_LENGTH]; int i=0; clrscr(); printf(“Enter a string:”); while ( ((ch=getche())!=’\r’) && (i < MAX_NAME_LENGTH … Read more

How to get the text from the HTML5 input field error message in Selenium?

The Selenium API doesn’t support directly a required field. However, you can easily get the state and the message with a piece of JavaScript (Java): JavascriptExecutor js = (JavascriptExecutor)driver; WebElement field = driver.findElement(By.name(“email”)); Boolean is_valid = (Boolean)js.executeScript(“return arguments[0].checkValidity();”, field); String message = (String)js.executeScript(“return arguments[0].validationMessage;”, field); Note that it’s also possible to use getAttribute to get … Read more

How to obtain the keycodes in Python

See tty standard module. It allows switching from default line-oriented (cooked) mode into char-oriented (cbreak) mode with tty.setcbreak(sys.stdin). Reading single char from sys.stdin will result into next pressed keyboard key (if it generates code): import sys import tty tty.setcbreak(sys.stdin) while True: print ord(sys.stdin.read(1)) Note: solution is Unix (including Linux) only. Edit: On Windows try msvcrt.getche()/getwche(). … Read more

Command Line Pipe Input in Java

By executing “java Read < input.txt” you’ve told the operating system that for this process, the piped file is standard in. You can’t then switch back to the command line from inside the application. If you want to do that, then pass input.txt as a file name parameter to the application, open/read/close the file yourself … Read more

Detect when “cursor position inside input change” in jQuery?

No, there is no event like “cursor position changed”. But if you want to know if the cursor position changed, you can do something like this: tested with jquery 1.7, i tested in Ie8 and chrome var last_position = 0; $(document).ready(function () { $(“#my_input”).bind(“keydown click focus”, function() { console.log(cursor_changed(this)); }); }); the console.log will return … Read more