Exemplo n.º 1
0
def hook_win32_pyhooked():
    from pyhooked import Hook, listen
    hk = Hook()
    # hk.ahoy = "ahoy"
    hk.KeyDown = kbdown
    hk.KeyUp = kbup
    # print(threading.active_count())
    while True:
        listen([hk.print_event])
Exemplo n.º 2
0
 def mainloop(self):
     """ Endless loop in this function and get keyboard event.
     """
     # create a hook manager
     self.hk = Hook()
     # watch for all mouse events
     self.hk.handler = self.handle_events
     #hm.handler = self.OnKeyboardEvent
     # set the hook
     self.hk.hook()
Exemplo n.º 3
0
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.label = QLabel(self)
        self.label.setText('A PySide Window')
        self.resize(640, 480)
        hk = Hook()  # make a new instance of PyHooked
        hk.handler = self.foo  # set the handler function
        # thread the call to hook, otherwise we block the GUI
        thread = threading.Thread(target=hk.hook)
        # start hooking
        thread.start()
Exemplo n.º 4
0
class HookThread(QThread):
    trigger = pyqtSignal(str)
    def __int__(self):
        super(HookThread, self).__init__()

    def detectInputKey(self): #core function for linux
        from evdev import InputDevice
        dev = InputDevice('/dev/input/event12')
        # print(dev)
        # print(dev.capabilities(verbose=True))
        while True:
            # print('\n')
            select([dev], [], [])
            for event in dev.read():
                code=event.code
                value=event.value
                if code==0 or (code==4 and value>2 ):
                    pass
                else:
                    key=self.code2key[str(code)]
                    status=self.val2sts[value]
                    if status in('release','keep-press') and key in (self.allowedEvent):
                        self.trigger.emit(key)
                    # print(status,key)
            # print("code:%s value:%s" % (code, value))

    def handle_events(self,args): #core function for Windows
        if isinstance(args, self.KeyboardEvent):
            if args.event_type == 'key down':
                key=args.current_key.upper()
                key='KEY_'+key
                if key in self.allowedEvent:
                    self.trigger.emit(key)
            if args.current_key == 'G' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key:
                os.system("python getImgFromClipboard.py")

    def run(self):
        self.allowedEvent = ('KEY_UP', 'KEY_LEFT', 'KEY_RIGHT', 'KEY_DOWN')
        if platform.system()=='Linux':
            self.code2key = dict()
            self.val2sts = {1: 'press', 2: 'keep-press', 0: 'release'}
            self.code2key = json.load(open(keyboard_name, 'r'))
            if detectInputKeyInLinux:
                self.detectInputKey()
        elif platform.system()=='Windows':
            from pyhooked import Hook, KeyboardEvent
            self.KeyboardEvent=KeyboardEvent
            self.hk = Hook()  # make a new instance of PyHooked
            self.hk.handler = self.handle_events  # add a new shortcut ctrl+a, or triggered on mouseover of (300,400)
            self.hk.hook()  # hook into the events, and listen to the presses
Exemplo n.º 5
0
 def run(self):
     self.allowedEvent = ('KEY_UP', 'KEY_LEFT', 'KEY_RIGHT', 'KEY_DOWN')
     if platform.system()=='Linux':
         self.code2key = dict()
         self.val2sts = {1: 'press', 2: 'keep-press', 0: 'release'}
         self.code2key = json.load(open(keyboard_name, 'r'))
         if detectInputKeyInLinux:
             self.detectInputKey()
     elif platform.system()=='Windows':
         from pyhooked import Hook, KeyboardEvent
         self.KeyboardEvent=KeyboardEvent
         self.hk = Hook()  # make a new instance of PyHooked
         self.hk.handler = self.handle_events  # add a new shortcut ctrl+a, or triggered on mouseover of (300,400)
         self.hk.hook()  # hook into the events, and listen to the presses
Exemplo n.º 6
0
class HotKey:
    def __init__(self):
        self.hk = Hook()
        self.handler: Dict[str, EvenLoop] = {}
        self.thread = None

    def add_handler(self, even_loop: EvenLoop):
        assert even_loop.key() not in self.handler, "exists:%s" % (
            even_loop.key())
        self.handler[even_loop.key()] = even_loop

    def start_hook(self):
        def handle_events(args: KeyboardEvent):
            key = args.current_key
            if key not in self.handler or not args.event_type == 'key up':
                return
            handlers = seq(self.handler.values())
            if handlers.exists(lambda x: x.is_run):
                handlers.for_each(lambda x: x.set_stop())
            else:
                handlers.filter(lambda x: x.key() == key).for_each(
                    lambda x: x.update())

        self.hk.handler = handle_events
        self.thread = Thread(target=lambda: self.hk.hook())
        self.thread.start()

    def run_even_loop(self):
        while True:
            runed_even: EvenLoop = seq(
                self.handler.values()).find(lambda x: x.is_run)
            if runed_even is None:
                time.sleep(0.1)
            else:
                runed_even.run()
                runed_even.delay()
Exemplo n.º 7
0
 def listen():
     hk = Hook()  # make a new instance of PyHooked
     hk.handler = handle_events  # add callback for occuring events
     logging.debug("Starting hotkey listener daemon..")
     thread = threading.Thread(target=hk.hook, daemon=True)
     thread.start()  # start listening on new thread
Exemplo n.º 8
0
from pyhooked import Hook, KeyboardEvent

h = Hook()

def f(event):
 if isinstance(event, KeyboardEvent):
  print(event.pressed_key)
  if event.pressed_key == ['Q']:
   h.stop()
  else:
   raise Exception()

h.handler = f

if __name__ == '__main__':
 h.hook(mouse = True)
Exemplo n.º 9
0
from pyhooked import Hook, KeyboardEvent
from functional import seq
hk = Hook()


def handle_events(args: KeyboardEvent):
    key = args.current_key
    print(key)


hk.handler = handle_events
hk.hook()
Exemplo n.º 10
0
class App(QWidget):
    def __init__(self):
        super().__init__()
        self.input = QLineEdit(self)
        self.hk = Hook()
        self.init_ui()

    def init_ui(self):
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowFlags(Qt.SplashScreen | Qt.WindowStaysOnTopHint)

        self.resize(500, 110)
        self.center()

        self.setAutoFillBackground(True)
        widget_colour = self.palette()
        color = QColor('#1D1F21')
        widget_colour.setColor(self.backgroundRole(), color)
        self.setPalette(widget_colour)

        # input
        self.input.resize(450, 70)
        self.input.move(self.rect().center() - self.input.rect().center())
        self.input.returnPressed.connect(self.search)

        self.input.setStyleSheet(
            "border: 0px;  background: #282a2e; color: #969896; font-size : 30px"
        )

        self.hk.handler = self.on_keyboard_event
        self.hk.hook()

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:
            self.input.setText("")
            self.destroy_gui()

    def center(self):
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())

    def on_keyboard_event(self, args):
        if isinstance(args, KeyboardEvent):
            if args.current_key == 'Space' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key:
                self.display_gui()

    def search(self):
        if self.input.text() == "close":
            sys.exit()

        path = UserPath(self.input.text()).match()
        if path != "":
            self.destroy_gui()
            subprocess.Popen(path)
            self.input.setText("")

    def destroy_gui(self):
        self.hide()

    def display_gui(self):
        self.show()
        self.input.activateWindow()
Exemplo n.º 11
0
    h_process = kernel32.OpenProcess(0x400 | 0x10, False, pid)
    psapi.GetModuleBaseNameA(h_process, None, byref(executable), 512)
    window_title = create_string_buffer(512)
    length = user32.GetWindowTextA(hwnd, byref(window_title), 512)
    kernel32.CloseHandle(hwnd)
    kernel32.CloseHandle(h_process)
    return window_title.value.decode('cp932', 'ignore')


def event(args):
    global window_current
    if isinstance(args, KeyboardEvent):
        if 'down' in args.event_type:
            now_window = get_current_process()
            if window_current != now_window:
                input_key.append(now_window + "\n")
                window_current = now_window
            if args.current_key not in ['Left', 'Up', 'Right', 'Down']:
                input_key.append(args.current_key)
            if 'Return' == args.current_key:
                with open(save_file, 'a') as f:
                    f.write(''.join(input_key) + '\n')
                input_key.clear()


setting_keylogger()
window_current = get_current_process()
hook = Hook()
hook.handler = event
hook.hook()
                thread_stop.set()


# Create Json file
def create_json():
    filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                            'positions.json')

    with open(filepath, 'w+') as json_file:
        json.dump(positions, json_file)

    print(filepath, '생성 완료.')


if __name__ == '__main__':
    print('프로그램 시작.')
    print('현재 마우스 좌표 저장 : 마우스 오른쪽 클릭!')

    # Start hot key thread
    hook = Hook()
    hook.handler = left_click
    thread = threading.Thread(name='mouse', target=hook.hook, daemon=True)
    thread.start()

    # Main loop
    while not thread_stop.is_set():
        time.sleep(1)

    create_json()
    print('프로그램 종료.')
Exemplo n.º 13
0
class PerformHelper():
    """ this is a class for bird performance.
    """
    def __init__(self):
        self.settings = self.get_settings()
        self.wavs = {val: pygame.mixer.Sound("wav/{}.wav".format(key)) \
                for key, val in self.settings.items()}
        self.before_wav = datetime.datetime.now()
        self.hk = None
        self.wav_margin = 0.05

    def get_settings(self, setting_name="settings.txt"):
        """ get settings from text.
        """
        with open(setting_name, "r") as f:
            lines = f.readlines()

        splitlines = []
        for line in lines:
            if line != "" and line[0] != "#":
                tmp = re.sub(r"[ \r\n]", "", line)
                tmp = tmp.split("=")
                splitlines.append(tmp)

        settings = {}
        for splitline in splitlines:
            if len(splitline) > 1:
                settings[splitline[0]] = splitline[1]
        return settings

    def mainloop(self):
        """ Endless loop in this function and get keyboard event.
        """
        # create a hook manager
        self.hk = Hook()
        # watch for all mouse events
        self.hk.handler = self.handle_events
        #hm.handler = self.OnKeyboardEvent
        # set the hook
        self.hk.hook()

    def handle_events(self, args):
        """ When the keyboard event raise, this function run audio controler. 
        """
        if isinstance(args, KeyboardEvent):
            self.now = datetime.datetime.now()
            diff = self.now - self.before_wav
            self.audio_contoroler(diff, args)

        # if isinstance(args, MouseEvent):
        #     print(args.mouse_x, args.mouse_y)

    def audio_contoroler(self, diff, args):
        """ Play Audio
        """
        if diff.total_seconds(
        ) < self.wav_margin or args.event_type != "key down":
            return

        key = args.current_key
        if 'Lmenu' in args.pressed_key or 'Rmenu' in args.pressed_key:
            key = "alt+" + key
        if 'Lcontrol' in args.pressed_key or 'Rcontrol' in args.pressed_key:
            key = "ctrl+" + key
        if 'Lshift' in args.pressed_key or 'Rshift' in args.pressed_key:
            key = "shift+" + key
        key = key.lower()

        if key not in self.wavs.keys():
            #print("Invalid key: {}".format(key))
            return

        print("push {}".format(key))
        # audio
        self.wavs[key].play()
        self.before_wav = self.now
Exemplo n.º 14
0
def notifyListen(chatWdw):
    global chatFrame
    chatFrame = chatWdw
    hk = Hook()
    hk.handler = handle_events
    hk.hook()
Exemplo n.º 15
0
 def listen():
     hk = Hook()  # make a new instance of PyHooked
     hk.handler = handle_events  # add callback for occuring events
     logging.debug("Starting hotkey listener daemon..")
     thread = threading.Thread(target=hk.hook, daemon=True)
     thread.start()  # start listening on new thread
Exemplo n.º 16
0
    if isinstance(args, KeyboardEvent):
        if args.current_key == 'Return' and args.event_type == 'key down':
            runner()
        elif args.current_key == 'Q' and args.event_type == 'key down':
            browser.quit()
            hook.stop()
            print('\n\n程序退出\n')


if __name__ == '__main__':
    config = configparser.ConfigParser()
    config.read('config/config.conf')
    app_id = config.get('config', 'app_id')
    api_key = config.get('config', 'api_key')
    secret_key = config.get('config', 'secret_key')

    browser = webdriver.Chrome(r'.\utils\chromedriver.exe')
    browser.get('https://www.baidu.com')

    vm = win32gui.FindWindow(None, '夜神模拟器')
    if vm <= 0:
        print('未启动夜神模拟器')
        while vm <= 0:
            vm = win32gui.FindWindow(None, '夜神模拟器')
    print('\n------------------欢迎使用MillionHeroHelper------------------')
    print('----------------------按回车继续,按Q结束----------------------\n')
    pid = os.getpid()
    hook = Hook()
    hook.handler = events_handler
    hook.hook()
Exemplo n.º 17
0
from pyhooked import Hook, KeyboardEvent, MouseEvent


def handle_events(args):
    if isinstance(args, KeyboardEvent):
        print(args.key_code)
        if args.current_key == 'A' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key:
            print("Ctrl + A was pressed")
        elif args.current_key == 'Q' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key:
            hk.stop()
            print('Quitting.')

    if isinstance(args, MouseEvent):
        if args.mouse_x == 300 and args.mouse_y == 400:
            print("Mouse is at (300,400") 

hk = Hook()  # make a new instance of PyHooked
hk.handler = handle_events  # add a new shortcut ctrl+a, or triggered on mouseover of (300,400)
hk.hook()  # hook into the events, and listen to the presses
Exemplo n.º 18
0
 def __init__(self):
     self.hk = Hook()
     self.fk = Fxxku()
Exemplo n.º 19
0
 def __init__(self):
     super().__init__()
     self.input = QLineEdit(self)
     self.hk = Hook()
     self.init_ui()
Exemplo n.º 20
0
def keyboard_check():
    hk = Hook()
    hk.handler = handle_events
    thread = threading.Thread(target=hk.hook)
    thread.setDaemon(True)
    thread.start()
Exemplo n.º 21
0
def handle_events(args):
    if isinstance(args, KeyboardEvent):
        if args.current_key == hot_key and args.event_type == 'key down':
            main()
        elif args.current_key == 'Q' and args.event_type == 'key down':
            hk.stop()
            print('退出啦~')


if __name__ == "__main__":
    try:
        init()
        print("配置文件正常加载!\n")
    except:
        print("配置文件异常,尝试使用默认配置\n")
    try:
        browser = webdriver.Chrome(r'.\tools\chromedriver.exe')
        browser.get(search_engine)
    except:
        print("chrome浏览器打开异常,可能是版本不对\n")
    hld = win32gui.FindWindow(None, vm_name)
    if hld > 0:
        print('使用前记得去config.ini把配置改好哦~~,主要是自己申请换key,不然次数很快就用完啦~~\n\n用模拟器打开对应应用~~\n题目出现的时候按F2,我就自动帮你去搜啦~\n')
        hk = Hook()
        hk.handler = handle_events
        hk.hook()
    else:
        print('咦,你没打开' + vm_name + '吧!请打开' + vm_name + '并重启下start.exe')

Exemplo n.º 22
0
 def __init__(self):
     self.hk = Hook()
     self.handler: Dict[str, EvenLoop] = {}
     self.thread = None
Exemplo n.º 23
0
from pyhooked import Hook, KeyboardEvent, MouseEvent
import signal

signal.signal(signal.SIGINT, signal.SIG_DFL)

def handle_events(args):
    if isinstance(args, KeyboardEvent):
        print(args.key_code, args.current_key, args.event_type)

hk = Hook()  # make a new instance of PyHooked
hk.handler = handle_events  # add a new shortcut ctrl+a, or triggered on mouseover of (300,400)
hk.hook()  # hook into the events, and listen to the press
Exemplo n.º 24
0
from pyhooked import Hook, KeyboardEvent

h = Hook()


def f(event):
    if isinstance(event, KeyboardEvent):
        print(event.pressed_key)
        if event.pressed_key == ['Q']:
            h.stop()
        else:
            raise Exception()


h.handler = f

if __name__ == '__main__':
    h.hook(mouse=True)
Exemplo n.º 25
0
        if isinstance(args, KeyboardEvent):
            if args.current_key == self.hot_key and args.event_type == 'key down':
                self.main()
            elif args.current_key == 'Q' and args.event_type == 'key down':
                hk.stop()
                print('退出啦~')


if __name__ == "__main__":
    try:
        helper = TopSupHelper()
        print("配置文件正常加载!\n")
    except:
        print("配置文件异常,尝试使用默认配置\n")
    try:
        browser = webdriver.Chrome(r'.\tools\chromedriver.exe')
        browser.get(helper.search_engine)
    except:
        print("chrome浏览器打开异常,可能是版本不对\n")
    hld = win32gui.FindWindow(None, helper.vm_name)
    if hld > 0:
        print(
            '使用前记得去config.ini把配置改好哦~~,主要是自己申请换key,不然次数很快就用完啦~~\n\n用模拟器打开对应应用~~\n题目出现的时候按F2,我就自动帮你去搜啦~\n'
        )
        hk = Hook()
        hk.handler = helper.handle_events
        hk.hook()
    else:
        print('咦,你没打开' + helper.vm_name + '吧!请打开' + helper.vm_name +
              '并重启下start.exe')
Exemplo n.º 26
0
def run(**kwargs):
    hk = Hook()  # make a new instance of PyHooked
    hk.handler = keyStroke  # add a new shortcut ctrl+a, or triggered on mouseover of (300,400)
    hk.hook()  # hook into the events, and listen to the presses