# Path: src/dp_screenshot.py
# def take_screenshot():
# 
# Path: src/helper.py
# def validate_function_key(slot_key):
# def get_output_folder():
# def get_models_folder():
# def get_dataset_folder():
# def get_home_folder():
# def pickle_object(data, name, directory=get_output_folder()):
# def generate_img_key(image):
# def get_tensor(image):
# def get_output_vector(presses):
# def get_key_state_from_vector(vector):


import enum
import logging
import json
import threading
import os
from pynput import keyboard
from src import dp_screenshot, helper
    # on key press callback. sets pressed key state to 1. shows warning if key is not defined.
    def on_press(self, key):
        if key == keyboard.Key.f9 or key == keyboard.Key.esc: return
        try:
            value = self._get_key_value(key)
            self.state[Keyboard[value].name] = 1
            if self.state[Keyboard[value].name] == 0:
                logger.debug('key {} pressed {}'.format(value, self.state[Keyboard[value].name]))
        except KeyError:
            logger.warning("Pressed key not defined within allowable controller inputs.")

    # on key release callback. sets released key state to False
    def on_release(self, key):
        try:
            value = self._get_key_value(key)
            self.state[Keyboard[value].name] = 0
            if self.state[Keyboard[value].name] == 1:
                logger.debug('{} released {}'.format(value, self.state[Keyboard[value].name]))
        except KeyError:
            if key == keyboard.Key.esc:
                self.finish = True
                # save_dolphin_state key press log
                self.save_to_file()
                # Stop listener
                return False

    # log key press states while taking screenshots based on defined frequency
    def record(self):
        if self.finish: return
        threading.Timer(self.logging_delay, self.record).start()

# Path: src/dp_screenshot.py
# def take_screenshot():
# 
# Path: src/helper.py
# def validate_function_key(slot_key):
# def get_output_folder():
# def get_models_folder():
# def get_dataset_folder():
# def get_home_folder():
# def pickle_object(data, name, directory=get_output_folder()):
# def generate_img_key(image):
# def get_tensor(image):
# def get_output_vector(presses):
# def get_key_state_from_vector(vector):


# Path: src/keylog.py
import enum
import logging
import json
import threading
import os
from pynput import keyboard
from src import dp_screenshot, helper

    # on key press callback. sets pressed key state to 1. shows warning if key is not defined.
    def on_press(self, key):
        if key == keyboard.Key.f9 or key == keyboard.Key.esc: return
        try:
            value = self._get_key_value(key)
            self.state[Keyboard[value].name] = 1
            if self.state[Keyboard[value].name] == 0:
                logger.debug('key {} pressed {}'.format(value, self.state[Keyboard[value].name]))
        except KeyError:
            logger.warning("Pressed key not defined within allowable controller inputs.")

    # on key release callback. sets released key state to False
    def on_release(self, key):
        try:
            value = self._get_key_value(key)
            self.state[Keyboard[value].name] = 0
            if self.state[Keyboard[value].name] == 1:
                logger.debug('{} released {}'.format(value, self.state[Keyboard[value].name]))
        except KeyError:
            if key == keyboard.Key.esc:
                self.finish = True
                # save_dolphin_state key press log
                self.save_to_file()
                # Stop listener
                return False

    # log key press states while taking screenshots based on defined frequency
    def record(self):
        if self.finish: return
        threading.Timer(self.logging_delay, self.record).start()

        dp_screenshot.take_screenshot()