Skip to content
Merged

Dev #159

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/dev_python3_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: python ./test/unit_test/screen/screen_test.py
- name: Test Screenshot
run: python ./test/unit_test/screen/screenshot_test.py
- name: Test Screen Get Pixel
run: python ./test/unit_test/screen/get_pixel_test.py
- name: Save Screenshot Image
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dev_python3_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: python ./test/unit_test/screen/screen_test.py
- name: Test Screenshot
run: python ./test/unit_test/screen/screenshot_test.py
- name: Test Screen Get Pixel
run: python ./test/unit_test/screen/get_pixel_test.py
- name: Save Screenshot Image
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/dev_python3_12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: python ./test/unit_test/screen/screen_test.py
- name: Test Screenshot
run: python ./test/unit_test/screen/screenshot_test.py
- name: Test Screen Get Pixel
run: python ./test/unit_test/screen/get_pixel_test.py
- name: Save Screenshot Image
uses: actions/upload-artifact@v4
with:
Expand Down
50 changes: 0 additions & 50 deletions .github/workflows/jekyll-gh-pages.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/stable_python3_10.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: python ./test/unit_test/screen/screen_test.py
- name: Test Screenshot
run: python ./test/unit_test/screen/screenshot_test.py
- name: Test Screen Get Pixel
run: python ./test/unit_test/screen/get_pixel_test.py
- name: Save Screenshot Image
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/stable_python3_11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: python ./test/unit_test/screen/screen_test.py
- name: Test Screenshot
run: python ./test/unit_test/screen/screenshot_test.py
- name: Test Screen Get Pixel
run: python ./test/unit_test/screen/get_pixel_test.py
- name: Save Screenshot Image
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/stable_python3_12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: python ./test/unit_test/screen/screen_test.py
- name: Test Screenshot
run: python ./test/unit_test/screen/screenshot_test.py
- name: Test Screen Get Pixel
run: python ./test/unit_test/screen/get_pixel_test.py
- name: Save Screenshot Image
uses: actions/upload-artifact@v4
with:
Expand Down
26 changes: 14 additions & 12 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "je_auto_control_dev"
version = "0.0.122"
version = "0.0.126"
authors = [
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
]
Expand Down
16 changes: 9 additions & 7 deletions je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from je_auto_control.utils.cv2_utils.screen_record import ScreenRecorder
# utils cv2_utils
from je_auto_control.utils.cv2_utils.screenshot import pil_screenshot
# Recording
from je_auto_control.utils.cv2_utils.video_recording import RecordingThread
from je_auto_control.utils.exception.exceptions import \
AutoControlActionException
from je_auto_control.utils.exception.exceptions import \
Expand Down Expand Up @@ -74,6 +76,8 @@
# timeout
from je_auto_control.utils.timeout.multiprocess_timeout import \
multiprocess_timeout
# Windows
from je_auto_control.windows.window import windows_window_manage
from je_auto_control.wrapper.auto_control_image import locate_all_image
from je_auto_control.wrapper.auto_control_image import locate_and_click
from je_auto_control.wrapper.auto_control_image import locate_image_center
Expand All @@ -85,29 +89,26 @@
from je_auto_control.wrapper.auto_control_keyboard import keyboard_keys_table
from je_auto_control.wrapper.auto_control_keyboard import press_keyboard_key
from je_auto_control.wrapper.auto_control_keyboard import release_keyboard_key
from je_auto_control.wrapper.auto_control_keyboard import send_key_event_to_window
from je_auto_control.wrapper.auto_control_keyboard import type_keyboard
from je_auto_control.wrapper.auto_control_keyboard import write
from je_auto_control.wrapper.auto_control_keyboard import send_key_event_to_window
# import mouse
from je_auto_control.wrapper.auto_control_mouse import click_mouse
from je_auto_control.wrapper.auto_control_mouse import get_mouse_position
from je_auto_control.wrapper.auto_control_mouse import mouse_keys_table
from je_auto_control.wrapper.auto_control_mouse import mouse_scroll
from je_auto_control.wrapper.auto_control_mouse import press_mouse
from je_auto_control.wrapper.auto_control_mouse import release_mouse
from je_auto_control.wrapper.auto_control_mouse import send_mouse_event_to_window
from je_auto_control.wrapper.auto_control_mouse import set_mouse_position
from je_auto_control.wrapper.auto_control_mouse import special_mouse_keys_table
from je_auto_control.wrapper.auto_control_mouse import send_mouse_event_to_window
# test_record
from je_auto_control.wrapper.auto_control_record import record
from je_auto_control.wrapper.auto_control_record import stop_record
# import screen
from je_auto_control.wrapper.auto_control_screen import screen_size
from je_auto_control.wrapper.auto_control_screen import screenshot
# Recording
from je_auto_control.utils.cv2_utils.video_recording import RecordingThread
# Windows
from je_auto_control.windows.window import windows_window_manage
from je_auto_control.wrapper.auto_control_screen import get_pixel

__all__ = [
"click_mouse", "mouse_keys_table", "get_mouse_position", "press_mouse", "release_mouse",
Expand All @@ -124,5 +125,6 @@
"generate_html", "generate_html_report", "generate_json", "generate_json_report", "generate_xml",
"generate_xml_report", "get_dir_files_as_list", "create_project_dir", "start_autocontrol_socket_server",
"callback_executor", "package_manager", "get_special_table", "ShellManager", "default_shell_manager",
"RecordingThread", "send_key_event_to_window", "send_mouse_event_to_window", "windows_window_manage"
"RecordingThread", "send_key_event_to_window", "send_mouse_event_to_window", "windows_window_manage",
"ScreenRecorder", "get_pixel"
]
10 changes: 9 additions & 1 deletion je_auto_control/linux_with_x11/screen/x11_linux_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
if sys.platform not in ["linux", "linux2"]:
raise AutoControlException(linux_import_error)

from Xlib import X
from je_auto_control.linux_with_x11.core.utils.x11_linux_display import display


def size() -> Tuple[int, int]:
"""
get screen size
"""
return display.screen().width_in_pixels, display.screen().height_in_pixels


def get_pixel_rgb(x: int, y: int) -> Tuple[int, int, int]:
root = display.Display().screen().root
root.get_image(x, y, 1, 1, X.ZPixmap, 0xffffffff)
raw = root.get_image(x, y, 1, 1, X.ZPixmap, 0xffffffff)
pixel = tuple(raw.data)[:3] # (R, G, B)
return pixel
61 changes: 61 additions & 0 deletions je_auto_control/osx/screen/osx_screen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import sys
import ctypes
from ctypes import c_void_p, c_double, c_uint32
from typing import Tuple

from je_auto_control.utils.exception.exception_tags import osx_import_error
Expand All @@ -15,3 +17,62 @@ def size() -> Tuple[int, int]:
get screen size
"""
return Quartz.CGDisplayPixelsWide((Quartz.CGMainDisplayID())), Quartz.CGDisplayPixelsHigh(Quartz.CGMainDisplayID())

def get_pixel(x: int, y: int) -> Tuple[int, int, int, int]:
# Load CoreGraphics and CoreFoundation frameworks
cg = ctypes.CDLL("/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics")
cf = ctypes.CDLL("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")

# Define CGRect structure as 4 doubles: x, y, width, height
CGRect = ctypes.c_double * 4

# Function signatures
cg.CGWindowListCreateImage.argtypes = [CGRect, c_uint32, c_uint32, c_uint32]
cg.CGWindowListCreateImage.restype = c_void_p

cg.CGImageGetDataProvider.argtypes = [c_void_p]
cg.CGImageGetDataProvider.restype = c_void_p

cg.CGDataProviderCopyData.argtypes = [c_void_p]
cg.CGDataProviderCopyData.restype = c_void_p

cf.CFDataGetLength.argtypes = [c_void_p]
cf.CFDataGetLength.restype = ctypes.c_long

cf.CFDataGetBytePtr.argtypes = [c_void_p]
cf.CFDataGetBytePtr.restype = ctypes.POINTER(ctypes.c_ubyte)

cf.CFRelease.argtypes = [c_void_p]
cf.CFRelease.restype = None

# Constants
kCGWindowListOptionOnScreenOnly = 1
kCGNullWindowID = 0
kCGWindowImageDefault = 0
rect = CGRect(x, y, 1.0, 1.0)
img = cg.CGWindowListCreateImage(rect,
kCGWindowListOptionOnScreenOnly,
kCGNullWindowID,
kCGWindowImageDefault)
if not img:
raise RuntimeError("Unable to capture screen image. Please ensure Screen Recording permission is granted.")

# Get the data provider from the image
provider = cg.CGImageGetDataProvider(img)
# Copy image data
cfdata = cg.CGDataProviderCopyData(provider)
# Get length of data
length = cf.CFDataGetLength(cfdata)
# Get pointer to byte data
buf = cf.CFDataGetBytePtr(cfdata)

# Default pixel format is BGRA
b, g, r, a = buf[0], buf[1], buf[2], buf[3]

# Release CoreFoundation objects to avoid memory leaks
cf.CFRelease(cfdata)
cf.CFRelease(provider)
cf.CFRelease(img)

return r, g, b, a

6 changes: 3 additions & 3 deletions je_auto_control/windows/core/utils/win32_ctype_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import ctypes
from ctypes import wintypes
from je_auto_control.windows.core.utils.win32_vk import win32_EventF_UNICODE, win32_VkToVSC
from je_auto_control.windows.core.utils.win32_vk import WIN32_EventF_UNICODE, WIN32_VkToVSC

user32 = ctypes.WinDLL('user32', use_last_error=True)

Expand Down Expand Up @@ -37,8 +37,8 @@ class KeyboardInput(ctypes.Structure):

def __init__(self, *args, **kwds):
super(KeyboardInput, self).__init__(*args, **kwds)
if not self.dwFlags & win32_EventF_UNICODE:
self.wScan = user32.MapVirtualKeyExW(self.wVk, win32_VkToVSC, 0)
if not self.dwFlags & WIN32_EventF_UNICODE:
self.wScan = user32.MapVirtualKeyExW(self.wVk, WIN32_VkToVSC, 0)


class HardwareInput(ctypes.Structure):
Expand Down
Loading