Initial work at making :fake-key work
This commit is contained in:
parent
e273f163a6
commit
79a337767a
@ -34,7 +34,7 @@ from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners
|
|||||||
from qutebrowser.config import config, configdata
|
from qutebrowser.config import config, configdata
|
||||||
from qutebrowser.browser import (urlmarks, browsertab, inspector, navigate,
|
from qutebrowser.browser import (urlmarks, browsertab, inspector, navigate,
|
||||||
webelem, downloads)
|
webelem, downloads)
|
||||||
from qutebrowser.keyinput import modeman
|
from qutebrowser.keyinput import modeman, keyutils
|
||||||
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
|
from qutebrowser.utils import (message, usertypes, log, qtutils, urlutils,
|
||||||
objreg, utils, standarddir)
|
objreg, utils, standarddir)
|
||||||
from qutebrowser.utils.usertypes import KeyMode
|
from qutebrowser.utils.usertypes import KeyMode
|
||||||
@ -2111,17 +2111,15 @@ class CommandDispatcher:
|
|||||||
keystring: The keystring to send.
|
keystring: The keystring to send.
|
||||||
global_: If given, the keys are sent to the qutebrowser UI.
|
global_: If given, the keys are sent to the qutebrowser UI.
|
||||||
"""
|
"""
|
||||||
# FIXME: rewrite
|
|
||||||
try:
|
try:
|
||||||
keyinfos = utils.parse_keystring(keystring)
|
sequence = keyutils.KeySequence.parse(keystring)
|
||||||
except utils.KeyParseError as e:
|
except keyutils.KeyParseError as e:
|
||||||
raise cmdexc.CommandError(str(e))
|
raise cmdexc.CommandError(str(e))
|
||||||
|
|
||||||
for keyinfo in keyinfos:
|
for keyinfo in sequence:
|
||||||
press_event = QKeyEvent(QEvent.KeyPress, keyinfo.key,
|
args = (keyinfo.key, keyinfo.modifiers, keyinfo.text())
|
||||||
keyinfo.modifiers, keyinfo.text)
|
press_event = QKeyEvent(QEvent.KeyPress, *args)
|
||||||
release_event = QKeyEvent(QEvent.KeyRelease, keyinfo.key,
|
release_event = QKeyEvent(QEvent.KeyRelease, *args)
|
||||||
keyinfo.modifiers, keyinfo.text)
|
|
||||||
|
|
||||||
if global_:
|
if global_:
|
||||||
window = QApplication.focusWindow()
|
window = QApplication.focusWindow()
|
||||||
|
@ -251,6 +251,13 @@ class KeyInfo:
|
|||||||
# "normal" binding
|
# "normal" binding
|
||||||
return normalized
|
return normalized
|
||||||
|
|
||||||
|
def text(self):
|
||||||
|
"""Get the text which would be displayed when pressing this key."""
|
||||||
|
text = QKeySequence(self.key).toString()
|
||||||
|
if not self.modifiers & Qt.ShiftModifier:
|
||||||
|
text = text.lower()
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
class KeySequence:
|
class KeySequence:
|
||||||
|
|
||||||
@ -327,6 +334,7 @@ class KeySequence:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def parse(cls, keystr):
|
def parse(cls, keystr):
|
||||||
"""Parse a keystring like <Ctrl-x> or xyz and return a KeySequence."""
|
"""Parse a keystring like <Ctrl-x> or xyz and return a KeySequence."""
|
||||||
|
# FIXME have multiple sequences in self!
|
||||||
s = ', '.join(_parse_keystring(keystr))
|
s = ', '.join(_parse_keystring(keystr))
|
||||||
new = cls(s)
|
new = cls(s)
|
||||||
assert len(new) > 0
|
assert len(new) > 0
|
||||||
|
Loading…
Reference in New Issue
Block a user