|
1 | 1 | PyLeapMouse
|
2 | 2 | ===========
|
3 | 3 |
|
4 |
| -wyager's Proof-of-concept code for a Leap Motion-based mouse controller. It now works with Linux, OS X and Windows. |
| 4 | +wyager's Proof-of-concept code for a Leap Motion-based mouse controller. It now works with Linux, OS X and Windows. |
5 | 5 |
|
6 |
| -The most recent version is on Github at github.com/openleap/pyleapmouse. |
| 6 | +The most recent version is on Github at github.com/openleap/pyleapmouse. |
7 | 7 |
|
8 |
| -###Configuration: |
9 |
| -1. Launch the Leap app (if not launched already) and plug in your Leap |
10 |
| -2. If you have not done so already, Configure your Leap screen from the Leap menu. |
11 |
| -3. WINDOWS USERS: You must copy the Leap.py file and all required library files (.libs and .dlls) from your Leap SDK folder to the "Windows" folder. These files are already included for OS X users, because OS X is 64-bit only. |
| 8 | +###Configuration: |
| 9 | +1. Launch the Leap app (if not launched already) and plug in your Leap |
| 10 | +2. If you have not done so already, Configure your Leap screen from the Leap menu. |
| 11 | +3. WINDOWS USERS: You must copy the Leap.py file and all required library files (.libs and .dlls) from your Leap SDK folder to the "Windows" folder. These files are already included for OS X users, because OS X is 64-bit only. |
12 | 12 | 4. LINUX USERS: You must copy the Leap.py file and all required library files (.sos) from your Leap SDK folder to the "Linux" folder (same reason as for Windows); alternatively, add the directory (or directories) containing them to your PYTHONPATH. Additionally, you must have the PyUserInput and Xlib Python modules installed.
|
13 |
| -5. `cd` to the directory all this stuff is in and run `python PyLeapMouse.py` (minus quotes) or just double-click PyLeapMouse.py if you have your computer configured to launch .py files. |
14 |
| -6. Launch with the --palm argument to run in palm mode (with much more accurate two-handed control). |
15 |
| - |
16 |
| -###Usage with Finger Mode (python PyLeapMouse.py --finger) (default): |
17 |
| -1. Insert your hand into frame. |
18 |
| -2. The forwardmost finger that the program detects is the mouse finger. Where it points, the cursor goes. |
19 |
| -3. Stick your thumb out (see note) to click down, and fold your thumb in to click up. |
20 |
| -4. Using two pointer fingers (e.g. index and middle) goes into scroll mode, which is not very intuitive but shows how it might work. The fingertips must be within a short distance of each other to activate scroll mode. |
21 |
| - |
22 |
| -###Usage with Palm Mode (python PyLeapMouse.py --palm): |
23 |
| -Operation is as follows: |
24 |
| -One hand in frame: The tilt of this hand moves the mouse. |
25 |
| -Two hands in frame: Left hand controls action. |
26 |
| - All fingers closed: Mouse movement with right hand tilt. |
27 |
| - One finger open: Clicking. Left mouse button is down. Mouse movement with right hand tilt. |
28 |
| - Two fingers open: Scrolling. Scrolling with right hand movement. |
29 |
| -This is a somewhat unintuitive method of operation, but I find that it gives exceptionally better control than the most obvious "point-at-screen" method of mouse control. With this two-handed tilt based mode, it is easy to hit and properly engage small buttons, scroll through webpages, etc. |
30 |
| - |
31 |
| -###Notes: |
32 |
| -This is a spare-time project, so it's not perfect quality. However, I tried to keep the code clean and readable. Let me know if you find any bugs (which there are certainly at least a few of). You can reach me at will (dot) yager (at) gmail (dot) (what the gmail domain ends in). |
33 |
| -The contents of the files are as follows: |
34 |
| -PyLeapMouse.py: The actual program |
35 |
| -FingerControl.py: Pointer-finger-control specific code |
36 |
| -PalmControl.py: Palm-tilt-control specific code |
37 |
| -Linux/OSX/Windows: |
38 |
| - Various OS-specific Leap library files |
39 |
| - Mouse.py: A set of generic commands and classes to abstract away from OS-Specific mouse commands |
40 |
| -Geometry.py: Geometric functions |
41 |
| -MiscFunctions.py: Things that aren't strictly geometry and aren't specific to any interface style |
42 |
| -README.md: You are here |
43 |
| - |
44 |
| -###Advanced Options: |
45 |
| -`--smooth-aggressiveness [value]` sets the number of samples to use for pointer finger mouse smoothing. |
46 |
| -`--smooth-falloff [value]` sets the rate at which previous samples lose importance. |
47 |
| -For every sample back in time, the previous location of the mouse is weighted with weight smooth_falloff^(-#sample). |
48 |
| -So if smooth_falloff = 1.2, the current frame has weight 1/(1.2^0)=1, but the frame from 5 frames ago has weight 1/(1.2^5) = .4 |
49 |
| -By default, the smooth aggressiveness is 8 frames with a falloff of 1.3. |
50 |
| - |
51 |
| -###TODO: |
52 |
| -Add proper relative mouse movement. Should be pretty easy on Windows, not sure how to do so on OS X. |
53 |
| -Add multiple monitor support for absolute mouse mode (and OS X's pseudo-relative mode). |
| 13 | +5. `cd` to the directory all this stuff is in and run `python PyLeapMouse.py` (minus quotes) or just double-click PyLeapMouse.py if you have your computer configured to launch .py files. |
| 14 | +6. Launch with the --palm argument to run in palm mode (with much more accurate two-handed control). |
| 15 | + |
| 16 | +###Usage with Finger Mode (python PyLeapMouse.py --finger) (default): |
| 17 | +1. Insert your hand into frame. |
| 18 | +2. The forwardmost finger that the program detects is the mouse finger. Where it points, the cursor goes. |
| 19 | +3. Stick your thumb out (see note) to click down, and fold your thumb in to click up. |
| 20 | +4. Using two pointer fingers (e.g. index and middle) goes into scroll mode, which is not very intuitive but shows how it might work. The fingertips must be within a short distance of each other to activate scroll mode. |
| 21 | + |
| 22 | +###Usage with Palm Mode (python PyLeapMouse.py --palm): |
| 23 | +Operation is as follows: |
| 24 | +One hand in frame: The tilt of this hand moves the mouse. |
| 25 | +Two hands in frame: Left hand controls action. |
| 26 | + All fingers closed: Mouse movement with right hand tilt. |
| 27 | + One finger open: Clicking. Left mouse button is down. Mouse movement with right hand tilt. |
| 28 | + Two fingers open: Scrolling. Scrolling with right hand movement. |
| 29 | +This is a somewhat unintuitive method of operation, but I find that it gives exceptionally better control than the most obvious "point-at-screen" method of mouse control. With this two-handed tilt based mode, it is easy to hit and properly engage small buttons, scroll through webpages, etc. |
| 30 | + |
| 31 | +###Usage with Motion Mode (python PyLeapMouse.py --motion): |
| 32 | +Movements are associated with commands listed in a file `commands.ini` placed at the root folder. Here is an example of what the file should look like : |
| 33 | + |
| 34 | + [screentap] |
| 35 | + |
| 36 | + [keytap] |
| 37 | + |
| 38 | + [swiperight] |
| 39 | + 1finger: rhythmbox-client --next |
| 40 | + 2finger: rhythmbox-client --next |
| 41 | + 3finger: rhythmbox-client --next |
| 42 | + 4finger: rhythmbox-client --next |
| 43 | + 5finger: rhythmbox-client --next |
| 44 | + |
| 45 | + [swipeleft] |
| 46 | + 1finger: rhythmbox-client --previous |
| 47 | + 2finger: rhythmbox-client --previous |
| 48 | + 3finger: rhythmbox-client --previous |
| 49 | + 4finger: rhythmbox-client --previous |
| 50 | + 5finger: rhythmbox-client --previous |
| 51 | + |
| 52 | + [clockwise] |
| 53 | + 1finger: rhythmbox-client --play |
| 54 | + 2finger: rhythmbox-client --play |
| 55 | + 3finger: rhythmbox-client --play |
| 56 | + 4finger: rhythmbox-client --play |
| 57 | + 5finger: rhythmbox-client --play |
| 58 | + |
| 59 | + [counterclockwise] |
| 60 | + 1finger: rhythmbox-client --pause |
| 61 | + 2finger: rhythmbox-client --pause |
| 62 | + 3finger: rhythmbox-client --pause |
| 63 | + 4finger: rhythmbox-client --pause |
| 64 | + 5finger: rhythmbox-client --pause |
| 65 | + |
| 66 | +Every commands could have a different behaviour if 1, 2, 3 ... 10 fingers are recognized but It's recommanded to use the same command for each number of fingers due to a lack of precision with Leap Motion. |
| 67 | + |
| 68 | +###Notes: |
| 69 | +This is a spare-time project, so it's not perfect quality. However, I tried to keep the code clean and readable. Let me know if you find any bugs (which there are certainly at least a few of). You can reach me at will (dot) yager (at) gmail (dot) (what the gmail domain ends in). |
| 70 | +The contents of the files are as follows: |
| 71 | +PyLeapMouse.py: The actual program |
| 72 | +FingerControl.py: Pointer-finger-control specific code |
| 73 | +PalmControl.py: Palm-tilt-control specific code |
| 74 | +Linux/OSX/Windows: |
| 75 | + Various OS-specific Leap library files |
| 76 | + Mouse.py: A set of generic commands and classes to abstract away from OS-Specific mouse commands |
| 77 | +Geometry.py: Geometric functions |
| 78 | +MiscFunctions.py: Things that aren't strictly geometry and aren't specific to any interface style |
| 79 | +README.md: You are here |
| 80 | + |
| 81 | +###Advanced Options: |
| 82 | +`--smooth-aggressiveness [value]` sets the number of samples to use for pointer finger mouse smoothing. |
| 83 | +`--smooth-falloff [value]` sets the rate at which previous samples lose importance. |
| 84 | +For every sample back in time, the previous location of the mouse is weighted with weight smooth_falloff^(-#sample). |
| 85 | +So if smooth_falloff = 1.2, the current frame has weight 1/(1.2^0)=1, but the frame from 5 frames ago has weight 1/(1.2^5) = .4 |
| 86 | +By default, the smooth aggressiveness is 8 frames with a falloff of 1.3. |
| 87 | + |
| 88 | +###TODO: |
| 89 | +Add proper relative mouse movement. Should be pretty easy on Windows, not sure how to do so on OS X. |
| 90 | +Add multiple monitor support for absolute mouse mode (and OS X's pseudo-relative mode). |
54 | 91 | Use PyUserInput for all mouse input? Or use Xlib directly for Linux?
|
0 commit comments