10 examples of 'python input enter key' in Python

Every line of 'python input enter key' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
191def key_input(self, window, key, scancode, codepoint, modifier):
192 if key == 27:
193 self.manager.go_back()
194 return True # back button now does nothing on Android
195 return False
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

96def key_pressed(event):
97 import string
98 if len(event.char) == 1 and (event.char.isalnum() or
99 event.char in string.punctuation):
100 editor.text.insert(Tkinter.INSERT, event.char)
101 elif event.keysym == 'space':
102 editor.text.insert(Tkinter.INSERT, ' ')
103 elif event.keysym == 'BackSpace':
104 editor.text.delete(Tkinter.INSERT + '-1c')
105 elif editor.text.compare(initial_cursor_position, '>', Tkinter.INSERT):
106 toplevel.destroy()
107 return
108 else:
109 return
110 new_name = editor.text.get(start_index, Tkinter.INSERT)
111 enhanced_list.clear()
112 for proposal in proposals:
113 if proposal.name.startswith(new_name):
114 enhanced_list.add_entry(proposal)
1860@handle(Keys.Any, filter=vi_digraph_mode & digraph_symbol_1_given)
1861def _(event: E) -> None:
1862 """
1863 Insert digraph.
1864 """
1865 try:
1866 # Lookup.
1867 code = (event.app.vi_state.digraph_symbol1, event.data)
1868 if code not in DIGRAPHS:
1869 code = code[::-1] # Try reversing.
1870 symbol = DIGRAPHS[code]
1871 except KeyError:
1872 # Unknown digraph.
1873 event.app.output.bell()
1874 else:
1875 # Insert digraph.
1876 overwrite = event.app.vi_state.input_mode == InputMode.REPLACE
1877 event.current_buffer.insert_text(chr(symbol), overwrite=overwrite)
1878 event.app.vi_state.waiting_for_digraph = False
1879 finally:
1880 event.app.vi_state.waiting_for_digraph = False
1881 event.app.vi_state.digraph_symbol1 = None
1589@handle(Keys.Backspace, filter=insert_multiple_mode)
1590def _(event):
1591 " Backspace, using multiple cursors. "
1592 buff = event.current_buffer
1593 original_text = buff.text
1594
1595 # Construct new text.
1596 deleted_something = False
1597 text = []
1598 p = 0
1599
1600 for p2 in buff.multiple_cursor_positions:
1601 if p2 > 0 and original_text[p2 - 1] != '\n': # Don't delete across lines.
1602 text.append(original_text[p:p2 - 1])
1603 deleted_something = True
1604 else:
1605 text.append(original_text[p:p2])
1606 p = p2
1607
1608 text.append(original_text[p:])
1609
1610 if deleted_something:
1611 # Shift all cursor positions.
1612 lengths = [len(part) for part in text[:-1]]
1613 new_cursor_positions = list(accumulate(lengths))
1614
1615 # Set result.
1616 buff.text = ''.join(text)
1617 buff.multiple_cursor_positions = new_cursor_positions
1618 buff.cursor_position -= 1
1619 else:
1620 event.cli.output.bell()
81def pressTest(self, key):
82 print( "-> Pressing " + key.upper() )
92def OnKeyPressCommand(self, widget, event):
93 """
94 Called when the user presses a key in the command entry.
95 Used for manipulating the command history.
96
97 Parameters:
98 widget -- GTK widget firing this event.
99 event -- keyboard event fired.
100
101 Returns:
102 True -- stop GTK signal propagation.
103 False -- continue GTK signal propagation.
104 """
105 key = gtk.gdk.keyval_name(event.keyval)
106
107 if key == "Up": # up arrow: show the previous command in the history
108 if len(self.history) > 0 and self.historyIndex+1 < len(self.history):
109 self.historyIndex += 1
110 self.command.set_text(self.history[self.historyIndex])
111 return True
112
113 elif key == "Down": # down arrow: show the next command in the history
114 if len(self.history) > 0 and self.historyIndex-1 >= -1:
115 self.historyIndex -= 1
116
117 if self.historyIndex >= 0:
118 self.command.set_text(self.history[self.historyIndex])
119 else:
120 self.command.set_text("")
121 return True
122
123 elif key == "Return": # enter key: create a new history entry and reset the index
124 self.historyIndex = -1
125 self.history.insert(0, self.command.get_text())
126 return False
127
128 else:
129 return False
58@handle('f2')
59def _(event):
60 """
61 Show/hide sidebar.
62 """
63 python_input.show_sidebar = not python_input.show_sidebar
64 if python_input.show_sidebar:
65 event.app.layout.focus(python_input.ptpython_layout.sidebar)
66 else:
67 event.app.layout.focus_last()
17def keypress(key):
18 #keyboard.press(key)
19 #keyboard.release(key)
20 os.system("xdotool key %s" % key)
406@handle(Keys.ControlS, filter= ~has_focus)
407def _(event):
408 get_search_state(event.cli).direction = IncrementalSearchDirection.FORWARD
409 event.cli.push_focus(SEARCH_BUFFER)
31def key_pressed_handler(self, event):
32 key = event.key()
33
34 if key == QtCore.Qt.Key_Tab:
35 self.handle_tab_key(event)
36 elif key in (
37 QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter, QtCore.Qt.Key_Space):
38 self.handle_complete_key(event)
39 elif key == QtCore.Qt.Key_Escape:
40 self.hide_completion_suggestions()

Related snippets