Code Monkey home page Code Monkey logo

ion-numworks's Introduction

Visitor Badge Downloads pip

Ion-numworks

This is just a little low level library for fetching keyboard input.
This is a porting of the Numworks module, and add other methods created by others OS (like Omega or Upsilon).

Installation

You can download it on pypi.org, download files of the latest release.
Or simply run this command to install library: pip install --pre ion-numworks

Also if you want to do it yourself, use this command to build and install the library automatically: python -m build && pip install .

More

Also i created the Kandinsky module of Numworks

Usable content

Numworks and Omega methods

keydown():

  • Parameters: k
  • Description: Return True if the k key is pressed (not release)

Upsilon methods (previous are also added)

get_keys():

  • Parameters: No parameters
  • Description: Get name of pressed keys

battery():

  • Parameters: No parameters
  • Description: Return battery voltage

battery_level():

  • Parameters: No parameters
  • Description: Return battery level

battery_ischarging():

  • Parameters: No parameters
  • Description: Return True if the battery is charging

set_brightness():

  • Parameters: level
  • Description: Set brightness level of screen

get_brightness():

  • Parameters: No parameters
  • Description: Get brightness level of screen

Associated keyboard keys

Numworks key Computer key Field name Field value
left Left KEY_LEFT 0
up Up KEY_UP 1
down Down KEY_DOWN 2
right Right KEY_RIGHT 3
OK Return KEY_OK 4
back Delete KEY_BACK 5
home Escape KEY_HOME 6
onOff End KEY_ONOFF 7
shift Shift KEY_SHIFT 12
alpha CTRL KEY_ALPHA 13
xnt X KEY_XNT 14
var V KEY_VAR 15
toolbox " KEY_TOOLBOX 16
backspace Backspace KEY_BACKSPACE 17
exp E KEY_EXP 18
ln N KEY_LN 19
log L KEY_LOG 20
imaginary I KEY_IMAGINARY 21
comma , KEY_COMMA 22
power ^ KEY_POWER 23
sin S KEY_SINE 24
cos C KEY_COSINE 25
tan T KEY_TANGENT 26
pi P KEY_PI 27
sqrt R KEY_SQRT 28
square > KEY_SQUARE 29
7 7 KEY_SEVEN 30
8 8 KEY_EIGHT 31
9 9 KEY_NINE 32
( ( KEY_LEFTPARENTHESIS 33
) ) KEY_RIGHTPARENTHESIS 34
4 4 KEY_FOUR 36
5 5 KEY_FIVE 37
6 6 KEY_SIX 38
* * KEY_MULTIPLICATION 39
/ / KEY_DIVISION 40
1 1 KEY_ONE 42
2 2 KEY_TWO 43
3 3 KEY_THREE 44
+ + KEY_PLUS 45
- - KEY_MINUS 46
0 0 KEY_ZERO 48
. . KEY_DOT 49
EE ! KEY_EE 50
Ans A KEY_ANS 51
EXE Insert KEY_EXE 52

Additional features

Environ options

/!\ You must make its additions before importing ion otherwise the changes will not take effect! /!\

You can also change some default option of library.
To do this, first import os module and add a compatibility check, like this:

try:
  import os
  if hasattr(os, "environ"):
    "<environ options here>"
except: pass
  • Change starting OS (methods according to the selected os will be created):
    (Option name is same as Kandinsky so that, if both libraries are present, they are synchronized)
# '0': All methods
# '1': Numworks methods
# '2': Omega method
# '3': Upsilon methods
os.environ['KANDINSKY_OS_MODE'] = '<number>'
  • Or if you want to not synchronize the library with kandinsky, use this environ name:
os.environ['ION_OS_MODE'] = '<number>'
  • Enable debug mode:
# Print full error stacktrace, the original pressed key and methods calls
os.environ['ION_ENABLE_DEBUG'] = ''
  • Disable reading inputs only in kandinsky window (if kandinsky is not imported globally, this option is enabled by default):
# This options allow to read keyboard inputs in python console and kandinsky window
# By default it just read kandinsky window (only if is focused)
# Note: if is not imported globally, this option is enabled by default
os.environ['ION_DISABLE_KANDINSKY_INPUT_ONLY'] = ''
  • Get keyboard inputs everywhere (not only in kandinsky window or python console):
# Allow to get inputs in entire system, like previous version of library
os.environ['ION_ENABLE_GET_INPUT_EVERYWHERE'] = ''

ion-numworks's People

Contributors

valmontechno avatar zetamap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

biloukass

ion-numworks's Issues

Stop script when window closes

Closing the Kandinsky window should interrupt the execution of the program because otherwise it may never stop or return an kandinsky window destroyed error.

Can't install package with pycharm

Bonjour, j'ai un petit soucis. Lorsque je veux installer ion-numworks directement dans pycharm, j'ai cette erreur et ça ne s'installe pas.

J'arrive pourtant à installer le package en suivant ce guide : https://www.jetbrains.com/help/pycharm/package-installation-issues.html#terminal

Collecting ion-numworks==2.0.dev4
Using cached ion_numworks-2.0.dev4-py3-none-any.whl.metadata (7.0 kB)
Collecting pynput (from ion-numworks==2.0.dev4)
Using cached pynput-1.7.6-py2.py3-none-any.whl.metadata (30 kB)
Collecting six (from pynput->ion-numworks==2.0.dev4)
Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
Collecting evdev>=1.3 (from pynput->ion-numworks==2.0.dev4)
Using cached evdev-1.7.0.tar.gz (30 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Installing backend dependencies: started
Installing backend dependencies: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Collecting python-xlib>=0.17 (from pynput->ion-numworks==2.0.dev4)
Using cached python_xlib-0.33-py2.py3-none-any.whl.metadata (6.2 kB)
Using cached ion_numworks-2.0.dev4-py3-none-any.whl (18 kB)
Using cached pynput-1.7.6-py2.py3-none-any.whl (89 kB)
Using cached python_xlib-0.33-py2.py3-none-any.whl (182 kB)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: evdev
Building wheel for evdev (pyproject.toml): started
Building wheel for evdev (pyproject.toml): finished with status 'error'
Failed to build evdev

error: subprocess-exited-with-error

× Building wheel for evdev (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [48 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-312
creating build/lib.linux-x86_64-cpython-312/evdev
copying evdev/init.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/device.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/ecodes.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/eventio.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/eventio_async.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/events.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/evtest.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/ff.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/genecodes.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/uinput.py -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/util.py -> build/lib.linux-x86_64-cpython-312/evdev
running egg_info
writing evdev.egg-info/PKG-INFO
writing dependency_links to evdev.egg-info/dependency_links.txt
writing top-level names to evdev.egg-info/top_level.txt
reading manifest file 'evdev.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no previously-included files found matching 'evdev/ecodes.c'
adding license file 'LICENSE'
writing manifest file 'evdev.egg-info/SOURCES.txt'
copying evdev/input.c -> build/lib.linux-x86_64-cpython-312/evdev
copying evdev/uinput.c -> build/lib.linux-x86_64-cpython-312/evdev
running build_ext
running build_ecodes
The 'linux/input.h' and 'linux/input-event-codes.h' include files
are missing. You will have to install the kernel header files in
order to continue:

      dnf install kernel-headers-$(uname -r)
      apt-get install linux-headers-$(uname -r)
      emerge sys-kernel/linux-headers
      pacman -S kernel-headers
  
  In case they are installed in a non-standard location, you may use
  the '--evdev-headers' option to specify one or more colon-separated
  paths. For example:
  
      python setup.py \
        build \
        build_ecodes --evdev-headers path/input.h:path/input-event-codes.h \
        build_ext --include-dirs path/ \
        install
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for evdev
ERROR: Could not build wheels for evdev, which is required to install pyproject.toml-based projects

Correction of a bug and modification.

In the list KEYS, the COMMA key has a space like that ", " so it doesn't work with is_pressed().
Also, the get_keys() doesn't work like in the calculator.
And I am sorry, I can't make a pull request.
So there is a proposition of modification for the program :

"""
This is the adaptation of Ion module of Numworks.
Please don't use keyboard and this module at the same time.
"""

v All keys of Numworks v

KEY_LEFT = 0
KEY_UP = 1
KEY_DOWN = 2
KEY_RIGHT = 3
KEY_OK = 4
KEY_BACK = 5
KEY_HOME = 6
KEY_ONOFF = 7
KEY_SHIFT = 12
KEY_ALPHA = 13
KEY_XNT = 14
KEY_VAR = 15
KEY_TOOLBOX = 16
KEY_BACKSPACE = 17
KEY_EXP = 18
KEY_LN = 19
KEY_LOG = 20
KEY_IMAGINARY = 21
KEY_COMMA = 22
KEY_POWER = 23
KEY_SINE = 24
KEY_COSINE = 25
KEY_TANGENT = 26
KEY_PI = 27
KEY_SQRT = 28
KEY_SQUARE = 29
KEY_SEVEN = 30
KEY_EIGHT = 31
KEY_NINE = 32
KEY_LEFTPARENTHESIS = 33
KEY_RIGHTPARENTHESIS = 34
KEY_FOUR = 36
KEY_FIVE = 37
KEY_FIVE = 38
KEY_MULTIPLICATION = 39
KEY_DIVISION = 40
KEY_ONE = 42
KEY_TWO = 43
KEY_THREE = 44
KEY_PLUS = 45
KEY_MINUS = 46
KEY_ZERO = 48
KEY_DOT = 49
KEY_EE = 50
KEY_ANS = 51
KEY_EXE = 52

KEYS=[
"left", "up", "down", "right", "return", "del", "home", "end", None, None,
None, None, "shift", "ctrl", ":", ";", """, "backspace", "[", "]",
"{", "}", ",", "^", "s", "c", "t", "p", "<", "²",
"7", "8", "9", "(", ")", None, "4", "5", "6", "*",
"/", None, "1", "2", "3", "+", "-", None, "0", ".",
"insert", "@", "enter"
]

^ All keys of Numworks ^

from keyboard import is_pressed

def keydown(key):
if key < 0 or key > 52 or KEYS[key] == None: return False
else: return is_pressed(KEYS[key])

def get_keys(): return [i for i in KEYS if i!=None and is_pressed(i)]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.