Skip to content

Commit

Permalink
improves: win_32 improve
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsneto committed Jan 10, 2024
1 parent 01c335e commit 3f9d0da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cereja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from . import experimental
from ._requests import request

VERSION = "1.9.7.final.0"
VERSION = "1.9.8.final.0"
__version__ = get_version_pep440_compliant(VERSION)


Expand Down
5 changes: 5 additions & 0 deletions cereja/hashtools/_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import binascii
import hashlib
import base64 as _b64
import secrets
from typing import Union

from cereja import string_to_literal
Expand Down Expand Up @@ -54,3 +55,7 @@ def is_base64(content):
return True
except binascii.Error:
return False


def random_hash(n_bytes):
return secrets.token_hex(nbytes=n_bytes)
18 changes: 15 additions & 3 deletions cereja/system/_win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,28 @@ class Keyboard:

__WM_KEYDOWN = 0x0100
__WM_KEYUP = 0x0101
MAX_TIME_SIMULE_KEY_PRESS = 1
MAX_TIME_SIMULE_KEY_PRESS = 0.05

def __init__(self, hwnd=None, is_async=False):
self.send_event = PostMessage if is_async else SendMessage
self._is_async = is_async
self.user32 = ctypes.windll.user32
self._stop_listen = True
self._hwnd = hwnd
self._max_time_simule_key_press = self.MAX_TIME_SIMULE_KEY_PRESS
self._key_press_callbacks = None


@property
def is_async(self):
return self._is_async

@is_async.setter
def is_async(self, v):
self._is_async = bool(v)

def send_event(self, *args, **kwargs):
(PostMessage if self._is_async else SendMessage)(*args, **kwargs)

@property
def max_time_key_press(self):
return self._max_time_simule_key_press
Expand Down Expand Up @@ -243,7 +255,7 @@ def _press_and_wait(self, key, secs):
def _press_n_times(self, key, n_times=1):
for _ in range(n_times):
self._key_down(key)
time.sleep(0.1 + (self._max_time_simule_key_press - (random.random() * self._max_time_simule_key_press)))
time.sleep(0.05 + (self._max_time_simule_key_press - (random.random() * self._max_time_simule_key_press)))
self._key_up(key)

def _key_press(self, key_code, n_times=1, secs=None):
Expand Down

0 comments on commit 3f9d0da

Please sign in to comment.