Python Forum
how to pause pyxhook keylogger
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to pause pyxhook keylogger
#1
Hello everybody.

New to python, I'm making a little application, with a keyboard listener (pyxhook). When user press "Enter" key, a video is shown on screen, but if the user press again "Enter", it's waiting for video to stop and then launched again...
How can I make the listener to pause until the video has ended ?

Here's my code :
#!/usr/bin/env python

import pygame
import sys
import time
import subprocess
import os
import requests
import youtube_dl
import pyxhook
import _thread
from pygame.locals import *

# MAXIMUM picture display sizes
max_width = 1600
max_height = 960
width = 0
height = 0

#color
black = (0,0,0)

pygame.init()     

def image(imagefile):
    image = pygame.image.load(imagefile)
    size = image.get_rect()
    width = size[2]
    height = size[3]
    windowSurfaceObj = pygame.display.set_mode((width,height),pygame.FULLSCREEN)
    windowSurfaceObj.blit(image,(0,0))
    pygame.display.update()

def video(myvideo):
    global black
    global videoRunning

    image("/home/pi/wait.png")
	command = 'youtube-dl --no-warnings -f mp4 -g ' + myvideo
	url = subprocess.check_output(command.split(), shell=False)
	realurl = url.decode("utf-8", "strict")[:-1]
	command = 'omxplayer -o local -b --no-osd --vol -2000 ' + realurl
	windowSurfaceObj = pygame.display.set_mode((width,height),pygame.FULLSCREEN)
	windowSurfaceObj.fill(black)
	pygame.display.update()
	video = subprocess.run(command.split(), shell=False)
	videoRunning = False
        
def kbevent(event):
    global videoRunning
    
    if event.Ascii ==13:
        if videoRunning:
            print("nothing, video running")
        else:
            print("run video")
            videoRunning = True
            myvideo='https://www.youtube.com/watch?v=B7bqAsxee4I'
            video(myvideo)
            image("/home/pi/home.png")
    elif event.Ascii ==27:
        if videoRunning:
            print("stop video")
            videoRunning=False
            os.system('killall omxplayer.bin')
            image("/home/pi/home.png")
        else:
            print("quit program")
            pygame.quit()
            sys.exit()
    else:
        pass

def listener():
    global running
    
    hookman = pyxhook.HookManager()
    hookman.KeyDown = kbevent
    hookman.HookKeyboard()
    hookman.start()
    running = True
    while running:
        time.sleep(0.1)
    hookman.cancel()

videoRunning=False
_thread.start_new_thread(listener, ())
image("/home/pi/home.png")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I pause only one object? actualpy 1 365 Feb-01-2024, 07:43 PM
Last Post: deanhystad
  How to pause execution (on windows)? pstein 1 559 Jun-23-2023, 06:58 PM
Last Post: rob101
  Is it Possible to pause a script? tester_V 6 1,516 Apr-05-2023, 06:11 AM
Last Post: tester_V
  Did subprocess.Popen() causes main routine to pause stdout? liudr 4 3,640 May-04-2021, 08:58 PM
Last Post: liudr
  Not able to make a specific thing pause in pygame cooImanreebro 4 3,210 Dec-13-2020, 10:34 PM
Last Post: cooImanreebro
  HELP: need a Keylogger with those features cocododo 1 1,961 May-03-2019, 12:33 AM
Last Post: micseydel
  keylogger help? (not for malicious use, to be used with data visualisation) dav3javu 1 2,025 Apr-19-2019, 11:13 PM
Last Post: keames
  How to Make Python code execution pause and resume to create .csv and read values. Kashi 2 3,762 Jun-14-2018, 04:16 PM
Last Post: DeaD_EyE
  How to pause/interupt with keyboard jehoshua 5 7,210 Mar-20-2018, 05:52 AM
Last Post: jehoshua
  Pause event Trajme 2 3,096 Dec-06-2017, 11:01 PM
Last Post: hshivaraj

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020