Skip to content

Commit faecbba

Browse files
New convenience method: press_release(code).
1 parent 9656d9c commit faecbba

4 files changed

Lines changed: 50 additions & 7 deletions

File tree

README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ General information
1818
- **Author**: `Tuomas Räsänen <http://tuos.codegrove.org/>`_ <tuos@codegrove.org>
1919
- **Homepage**: http://codegrove.org/python-uinput/
2020
- **License**: LGPLv3+ (see COPYING for details)
21-
- **Version**: 0.1
21+
- **Version**: 0.2
2222

2323
Requirements
2424
============
@@ -29,7 +29,7 @@ Requirements
2929

3030
sudo apt-get install python2.6-dev
3131

32-
- `libsuinput-0.1 <http://codegrove.org/libsuinput/0.1/>`_
32+
- `libsuinput-0.2 <http://codegrove.org/libsuinput/0.2/>`_
3333

3434
Example usage
3535
=============
@@ -44,7 +44,7 @@ To create and use an uinput driver::
4444
Downloading
4545
===========
4646

47-
- Tarball is available at: http://codegrove.org/python-uinput/0.1/python-uinput-0.1.tar.gz
47+
- Tarball is available at: http://codegrove.org/python-uinput/0.2/python-uinput-0.2.tar.gz
4848
- Latest sources from public git-repository: http://github.com/tuos/python-uinput/ ::
4949

5050
git clone git://github.com/tuos/python-uinput.git

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
sources=['src/codes.c'])
1515

1616
setup(name='python-uinput',
17-
version='0.1',
17+
version='0.2',
1818
description='Simple Python API to the Linux uinput-system.',
1919
author='Tuomas Räsänen',
2020
author_email='tuos@codegrove.org',
2121
url='http://codegrove.org/python-uinput/',
22-
download_url='http://codegrove.org/python-uinput/0.1/python-uinput-0.1.tar.gz',
22+
download_url='http://codegrove.org/python-uinput/0.2/python-uinput-0.2.tar.gz',
2323
package_dir={'uinput': 'src'},
2424
packages=['uinput'],
2525
ext_modules=[pysuinput_module, codes_module],

src/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,23 @@ def click(self, uinput_code):
127127
uinput.codes -module.
128128
129129
This method is provided as a convenience and has effectively the
130-
same result as calling press(uinput_fd) and release(uinput_fd)
131-
sequentially.
130+
same result as calling press() and release() sequentially.
132131
"""
133132
_suinput.click(self._input_fd, uinput_code)
134133

134+
def press_release(self, signed_uinput_code):
135+
"""Sends a press or a release event to the event device. The sign
136+
of the `signed_uinput_code` determines which type of event is sent.
137+
Positive `signed_uinput_code` means press and negative means release.
138+
139+
Absolute value of `signed_uinput_code` must be one of the constant
140+
values defined in uinput.codes -module.
141+
142+
This method is provided as a convenience and has effectively the
143+
same result as calling press() when the value of `signed_uinput_code`
144+
is positive and release() when negative.
145+
"""
146+
_suinput.press_release(self._input_fd, signed_uinput_code)
147+
135148
def __del__(self):
136149
_suinput.close(self._input_fd)

src/pysuinput.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ static PyObject* pysuinput_move_pointer(PyObject *self, PyObject *args)
9494
Py_RETURN_NONE;
9595
}
9696

97+
static PyObject* pysuinput_press_release(PyObject *self, PyObject *args)
98+
{
99+
int uinput_fd;
100+
int16_t code;
101+
if (!PyArg_ParseTuple(args, "ih", &uinput_fd, &code))
102+
return NULL;
103+
if (suinput_press_release(uinput_fd, code) == -1)
104+
return PyErr_SetFromErrno(PyExc_IOError);
105+
Py_RETURN_NONE;
106+
}
107+
97108
static PyMethodDef pysuinputMethods[] = {
98109
{"open", pysuinput_open, METH_VARARGS,
99110
"open(str(name), int(bustype), int(vendor), int(product), int(version))\n\n"
@@ -165,6 +176,25 @@ static PyMethodDef pysuinputMethods[] = {
165176
"suinput_open()."
166177
},
167178

179+
{"press_release", pysuinput_press_release, METH_VARARGS,
180+
"press_release(int(uinput_fd), int(signed_code))\n\n"
181+
"Sends a press or a release event to the event device. The sign of\n"
182+
"`code` determines which type of event is sent. Positive `code`\n"
183+
"means press and negative `code` means release. Returns 0 on\n"
184+
"success. On error, -1 is returned, and errno is set appropriately.\n"
185+
"\n"
186+
"Behaviour is undefined when passed a file descriptor not returned by\n"
187+
"suinput_open().\n"
188+
"\n"
189+
"All possible absolute values of `code` are defined as constants in\n"
190+
"uinput.codes -module.\n"
191+
"\n"
192+
"This function is provided as a convenience and has effectively the\n"
193+
"same result as calling suinput_press() when the value of `code` is\n"
194+
"positive and suinput_release() when negative."
195+
196+
},
197+
168198
{NULL, NULL, 0, NULL}
169199
};
170200

0 commit comments

Comments
 (0)