Exiting while loop by pressing enter without blocking. How can I improve this method?

This worked for me: import sys, select, os i = 0 while True: os.system(‘cls’ if os.name == ‘nt’ else ‘clear’) print “I’m doing stuff. Press Enter to stop me!” print i if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: line = raw_input() break i += 1 You only need to check for the stdin being input … Read more

Disable New Line in Textarea when Pressed ENTER

try this $(“textarea”).keydown(function(e){ // Enter was pressed without shift key if (e.keyCode == 13 && !e.shiftKey) { // prevent default behavior e.preventDefault(); } }); update your fiddle to $(“.Post_Description_Text”).keydown(function(e){ if (e.keyCode == 13 && !e.shiftKey) { // prevent default behavior e.preventDefault(); //alert(“ok”); return false; } });

Default action to execute when pressing enter in a form

This is not specific to JSF. This is specific to HTML. The HTML5 forms specification section 4.10.22.2 basically specifies that the first occuring <input type=”submit”> element in the “tree order” in same <form> as the current input element in the HTML DOM tree will be invoked on enter press. There are basically two workarounds: Use … Read more

Submit form on pressing Enter with AngularJS

Angular supports this out of the box. Have you tried ngSubmit on your form element? <form ng-submit=”myFunc()” ng-controller=”mycontroller”> <input type=”text” ng-model=”name” /> <br /> <input type=”text” ng-model=”email” /> </form> EDIT: Per the comment regarding the submit button, see Submitting a form by pressing enter without a submit button which gives the solution of: <input type=”submit” … Read more

Prevent form submission on Enter key press

event.key === “Enter” More recent and much cleaner: use event.key. No more arbitrary number codes! NOTE: The old properties (.keyCode and .which) are Deprecated. const node = document.getElementsByClassName(“mySelect”)[0]; node.addEventListener(“keydown”, function(event) { if (event.key === “Enter”) { event.preventDefault(); // Do more work } }); Modern style, with lambda and destructuring node.addEventListener(“keydown”, ({key}) => { if (key … Read more

tech