10 examples of 'python key pressed' in Python

Every line of 'python key pressed' 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
17def keypress(key):
18 #keyboard.press(key)
19 #keyboard.release(key)
20 os.system("xdotool key %s" % key)
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)
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
81def pressTest(self, key):
82 print( "-> Pressing " + key.upper() )
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()
95@handle(Keys.ControlP)
96def _(event):
97 " Previous line. "
98 event.current_buffer.auto_up(count=event.arg)
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()
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
182@handle("escape", "a")
183def _(event: E) -> None:
184 " Previous sentence. "
63@motion
64def keypress_k(self, count):
65 row, column = self.editor.active_window.cursor
66 return row - count, column

Related snippets