S
S
Sarkian2013-11-15 12:46:57
Python
Sarkian, 2013-11-15 12:46:57

PyQt QWebView - keyboard events and layout

How to catch keystrokes regardless of keyboard layout?


window.addEventListener('keydown', function(e) {
    console.log(e.keyCode);
    // в браузерах не зависит от раскладки,
    // но в QWebView при русской раскладке keyCode == 0
});


# coding: utf-8
# Last Change: 2013 Nov 15, 12:22

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *


class View(QWebView):

    def __init__(self, parent=None):
        super(QWebView, self).__init__(parent)

    def keyPressEvent(self, e):
        print e.key() # зависит от раскладки
        print e.nativeScanCode() # не зависит от раскладки, но 
                                 # другие коды и (как я вычитал) не работает на маке
        #QWebView.keyPressEvent(self, e)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question