Last active
May 29, 2024 17:36
-
-
Save kelvinmenegasse/f4b49342403394940c2e35791b9725a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
# Configura o webdriver do Selenium para usar o Firefox | |
driver = webdriver.Firefox() | |
# Abre uma página | |
driver.get('http://example.com') | |
# Injeta JavaScript para bloquear a tecla Tab | |
from selenium import webdriver | |
# Configura o webdriver do Selenium para usar o Firefox | |
driver = webdriver.Firefox() | |
# Abre uma página | |
driver.get('http://example.com') | |
# Injeta JavaScript para bloquear as teclas especificadas nos eventos keydown e keypress | |
driver.execute_script(""" | |
// Função para adicionar ouvintes de eventos e bloquear teclas | |
function blockKeys() { | |
// Lista de códigos das teclas a serem bloqueadas: Tab, Alt, Windows/Super, e teclas F1 a F12 | |
var blockedKeys = [9, 18, 91, 92, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123]; | |
// Função para lidar com o bloqueio das teclas | |
function handleKeyEvent(event) { | |
// Verifica se a tecla pressionada está na lista bloqueada ou se Ctrl ou Alt estão pressionados | |
if (blockedKeys.includes(event.keyCode) || event.ctrlKey || event.altKey) { | |
event.preventDefault(); // Impede o comportamento padrão da tecla | |
event.stopPropagation(); // Impede que o evento se propague mais | |
} | |
} | |
// Adiciona os ouvintes para os eventos keydown e keypress | |
document.addEventListener('keydown', handleKeyEvent); | |
document.addEventListener('keypress', handleKeyEvent); | |
} | |
// Executa a função de bloqueio de teclas | |
blockKeys(); | |
""") | |
# O script permanecerá ativo enquanto a página estiver aberta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment