Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 19 Sep 2014, 00:09
All times are UTC - 4
 Forum index » Advanced Topics » Puppy Projects
OneSwitch pet - control a PC using a single switch
Moderators: Flash, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 6 [84 Posts]   Goto page: 1, 2, 3, 4, 5, 6 Next
Author Message
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Mon 11 Mar 2013, 17:30    Post subject:  OneSwitch pet - control a PC using a single switch
Subject description: Radar and Navbar scripts to control cursor movement from a single keyboard key or switch
 

[AMENDMENT: 2013-07-16]

This thread concerns developing a tool to control mouse cursor movement using only single key/switch.
It was a part of another thread initially, but it has been split.

Original idea came from Will (standard7452) in this thread: Need on-screen keyboard with mouse functions

The latest OneSwitch package is attached to this post.
________________

Update, version-1.2:
Added "Scan" button to Radar/NavBar GUIs (thanks to Greengeek for the idea), what makes possible to automatically configure proper input device and a switch keycode.
The 'keyhunter' script will be also launched right after installing the .pet.

Update, version 1.3:
- a small correction in keyhunter script (sometimes Radar/NavBar wasn't restarted properly, hope it'll be ok now);
- added circular mode of scanning in XVKBD mode (only in Radar).
This feature has been done some time ago as a separate Radar version for use with Mike's custom Xvkbd layouts.
So now it's been merged into the main OneSwitch package.


________________________________

(original/previous content)

greengeek wrote:
BTW - My reason for wanting these scripts to help with mouse movement is to allow an inexperienced or physically challenged user to easily select between a limited number of mousepointer_position_choices. That way they can have some degree of functionality by having a "mouseclick" button, but no actual ability to move the mouse anywhere I don't want it to go.

I saw that thread.
Been thinking a while about that and about how you want to employ xdotool and came up with this; perhaps it will help you a bit with the task, somehow..?

First, using xbindkeys (it's OOTB in Slacko) bind, for example, "pause/break" key (OP has mentioned about this key) with echo true > /tmp/button_press_signal command (see screenshot, I also use xbindkeys-config GUI).

And the script works this way:
1. It moves cursor right until pause/break key is pressed.
2. Then stops for a while (0.5s) and starts moving cursor down until pause/break key is pressed.
3. Then "left-click" signal is sent and cursor stays in place until pause/break key is pressed again - and the loop continues.

Maybe this description is a bit fuzzy, but when you see how it works everything will be clear. Cool
BTW, launch this script from a terminal window to have fast and easy way to terminate it (CTRL+C).

Code:
#!/bin/bash

# Req.: xdotool and xbindkeys
# Note: bind a dead key, for exmample 'pause/break' with the following command:
# echo true > /tmp/button_press_signal

# -----------------------------------------------------------------------------
STEP=5            # X/Y leap
SPEED=0.1         # speed (0.1s)
# -----------------------------------------------------------------------------

# Temporary file for inter-communication
PRESS=/tmp/button_press_signal
# Make this file empty initially
: > $PRESS

# Read current screen resolution
read MAXX MAXY <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {print $2}'`

# Infinite loop
while :; do
  X=0
  Y=10
 
  # Loop: If tempfile is empty - move cursor right
  until [ -s $PRESS ]; do
    X=$(($X+$STEP)); [ "$X" -ge "$MAXX" ] && X=0   # increase X coordinate
    xdotool mousemove $X $Y
    sleep $SPEED
  done
 
  : > $PRESS      # reset tempfile
  sleep 0.5
 
  # Loop: If tempfile is empty - move cursor down
  until [ -s $PRESS ]; do
    Y=$(($Y+$STEP)); [ "$Y" -ge "$MAXY" ] && Y=10   # increase Y coordinate
    xdotool mousemove $X $Y
    sleep $SPEED
  done
 
  : > $PRESS      # reset tempfile
  Y=$(($Y-$STEP))   # needed to refine coordinates
 
  xdotool click 1   # left-click
 
  # If tempfile is empty - do nothing
  until [ -s $PRESS ]; do
    sleep $SPEED
  done
 
  : > $PRESS      # reset tempfile

done

PS. Of course you can modify initial coordinates, max. range and step, to limit the mouse movement to given area.

Greetings![/img]
OneSwitch-1.3.pet
Description 
pet

 Download 
Filename  OneSwitch-1.3.pet 
Filesize  94.66 KB 
Downloaded  229 Time(s) 
Screenshot.png
 Description   
 Filesize   71.57 KB
 Viewed   731 Time(s)

Screenshot.png


_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.

Last edited by SFR on Thu 25 Jul 2013, 14:21; edited 4 times in total
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Mon 11 Mar 2013, 22:14    Post subject:  

oooooh, that looks tasty! Thanks for that. It's a different way of achieving what I had in mind, but probably more useful than the way I'm currently going about it.

I will get my teeth into your script at some stage and see how I can graft it into my proposed system. Thanks!

EDIT:
SFR wrote:
BTW, launch this script from a terminal window to have fast and easy way to terminate it (CTRL+C).
Good idea. I'm getting tired of having to try and launch Htop to identify and kill my mousebouncing script while my mouse is bouncing up and down Smile
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4351

PostPosted: Tue 12 Mar 2013, 11:04    Post subject:  

SFR wrote:
Code:
read MAXX MAXY <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {print $2}'`
I see you've been honing your scripting 5|<I|_|_2 - nice work
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Tue 12 Mar 2013, 14:40    Post subject:  

technosaurus wrote:
SFR wrote:
Code:
read MAXX MAXY <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {print $2}'`
I see you've been honing your scripting 5|<I|_|_2 - nice work

I'm trying indeed, thanks for noticing that!
6R3372 Wink

@ Greengeek
Just another idea that you may find useful.
I just saw this video and wondered if it would be possible to implemet something similar (I'm talking about cursor movement) in Bash/Gtkdialog.
This crude script only moves cursor and does nothing more, but it shows that it's possible indeed.

Usage:
1. Wait for desired direction and press Pause/Break
2. Cursor will be moving until you press Pause/Break again and we're going back to 1.

Code:
#!/bin/bash

# Req.: Gtkdialog >= 0.8.0, xdotool, xbindkeys, xwininfo, getcurpos, bc, awk
# Note: bind a dead key, for exmample 'pause/break' with the following command:
# echo true > /tmp/button_press_signal

TEMPDIR=/dev/shm/one_switch_temp
mkdir $TEMPDIR

# Delete tempdir or exit
trap 'rm -rf $TEMPDIR' EXIT

PRESS=/tmp/button_press_signal
: > $PRESS

export PIC=$TEMPDIR/cursor_pic
export ROTATION=$TEMPDIR/cursor_rotate
echo 0 > $ROTATION

rotate_line () {
read DEG < $ROTATION
RAD="`echo 'scale=2; '$DEG' * 3.14 / 180' | bc -l`"
LX="`echo 'scale=2; 32 + 24 * c('$RAD')' | bc -l`"
LY="`echo 'scale=2; 32 + 24 * s('$RAD')' | bc -l`"

DEG=$(($DEG+5))
[ "$DEG" -ge 360 ] && DEG=0
echo $DEG > $ROTATION

# Create svg pic
echo '<svg width="64" height="64" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<circle cx="32" cy="32" r="24" stroke="red" fill="none" stroke-width="3" />
<line x1="32" y1="32" x2="'$LX'" y2="'$LY'" stroke="black" stroke-width="3" />
</svg>' > $PIC
}
export -f rotate_line

# First call just to make a picture
rotate_line

# Read current screen resolution
read MAXX MAXY <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {print $2}'`

# Gtkdialog window
export PREVIEW='
<window decorated="false" skip-pager-hint="true" skip-taskbar-hint="true" resizable="false">
  <pixmap>
    <variable>PICTURE</variable>
    <input file>'"$PIC"'</input>
  </pixmap>
  <timer visible="false" milliseconds="true" interval="100">
    <action>rotate_line</action>
    <action>refresh:PICTURE</action>
  </timer>
</window>
'

# Infinite loop
while :; do
 
  # Current cursor position
  read CX CY <<< `getcurpos`
  CX=$(($CX-32)); [ $CX -lt 0 ] && CX=0
  CY=$(($CY-32)); [ $CY -lt 0 ] && CY=0
 
  # Show window
  gtkdialog -G 64x64+$CX+$CY -p PREVIEW & GTKPID=$!
 
  # Wait for switch signal
  until [ -s $PRESS ]; do
    sleep 0.1
  done
 
  # Kill Gtkdialog window
  kill $GTKPID

  : > $PRESS
 
  read DEG < $ROTATION
  DEG=$(($DEG+85))
 
  # Move cursor until switch signal will appear again
  until [ -s $PRESS ]; do
    xdotool mousemove_relative --polar $DEG 5
    sleep 0.1
  done
 
  : > $PRESS
 
done

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Tue 12 Mar 2013, 15:30    Post subject:  

EDIT : I was posting this when you made your newer post... I am referring here to your first script...

SFR wrote:
And the script works this way:..

I think this has a lot of potential. Do you think it would be possible to modify that script so that it has a coarse mode and a fine mode? By this I mean it would scroll quite fast initially ("coarse mode") in order to pinpoint the general area of the screen you wanted to click on, then drop immediately into "fine" mode where the scroll speed would be much slower, and limited to, say, a 2cm square around the "coarse select" point?

(My thinking is that your script would be the "default mode" that the PC would drop back to every time there was no "mouseclick" input for, say, 20 seconds - which would then allow the user to zone in on any part of the screen (not just the onscreen keyboard) and begin whatever task they wanted. The onscreen keyboard would then be only one of several input modes available to the user, all controlled by your SFRmouse script as the default)
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Tue 12 Mar 2013, 15:40    Post subject:  

Yeah, that Tilvus line cursor is a good idea. Not necessary to have a line though - although that obviously does help clarity (and their nudge function is well thought out..).
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Tue 12 Mar 2013, 16:19    Post subject:  

greengeek wrote:
EDIT : I was posting this when you made your newer post... I am referring here to your first script...

SFR wrote:
And the script works this way:..

I think this has a lot of potential. Do you think it would be possible to modify that script so that it has a coarse mode and a fine mode? By this I mean it would scroll quite fast initially ("coarse mode") in order to pinpoint the general area of the screen you wanted to click on, then drop immediately into "fine" mode where the scroll speed would be much slower, and limited to, say, a 2cm square around the "coarse select" point?

You mean something like:
1. Looped cursor movement right (coarse) within fullscreen
2. Looped cursor movement down (coarse) within fullscreen
3. Looped cursor movement right (fine) within reduced area
4. Looped cursor movement down (fine) within reduced area
5. Left-click
6. GOTO 1
?
If so, it's just a matter of two additional loops; could be like this:
Code:
#!/bin/bash

# Req.: xdotool and xbindkeys
# Note: bind a dead key, for exmample 'pause/break' with the following command:
# echo true > /tmp/button_press_signal

# -----------------------------------------------------------------------------
STEP_COARSE=64
STEP_FINE=4      
SPEED_COARSE=0.5
SPEED_FINE=0.1
# -----------------------------------------------------------------------------

# Temporary file for inter-communication
PRESS=/tmp/button_press_signal
# Make this file empty initially
: > $PRESS

# Read current screen resolution
read MAXX MAXY <<< `xwininfo -root | awk 'NR>=8&&NR<=9 {print $2}'` 

# Infinite loop
while :; do
  X=0
  Y=10
 
  # ======
  # COARSE
  # ======
  until [ -s $PRESS ]; do
    X=$(($X+$STEP_COARSE)); [ $X -ge $MAXX ] && X=0
    xdotool mousemove $X $Y
    sleep $SPEED_COARSE
  done
  : > $PRESS
  sleep 0.5
  until [ -s $PRESS ]; do
    Y=$(($Y+$STEP_COARSE)); [ $Y -ge $MAXY ] && Y=10
    xdotool mousemove $X $Y
    sleep $SPEED_COARSE
  done
  : > $PRESS
 
  # Reduce area to 64x64
  X1=$(($X-32)); [ $X1 -lt 0 ] && X1=0
  Y1=$(($Y-32)); [ $Y1 -lt 0 ] && Y1=0
  X2=$(($X+32)); [ $X2 -gt $MAXX ] && X2=$MAXX
  Y2=$(($Y+32)); [ $Y2 -gt $MAXY ] && Y2=$MAXY
 
  # ====
  # FINE
  # ====
  until [ -s $PRESS ]; do
    X=$(($X+$STEP_FINE)); [ $X -ge $X2 ] && X=$X1
    xdotool mousemove $X $Y
    sleep $SPEED_FINE
  done
  : > $PRESS
  sleep 0.5
  until [ -s $PRESS ]; do
    Y=$(($Y+$STEP_FINE)); [ $Y -ge $Y2 ] && Y=$Y1
    xdotool mousemove $X $Y
    sleep $SPEED_FINE
  done
  : > $PRESS
 
  xdotool click 1   # left-click
 
  # If tempfile is empty - do nothing
  until [ -s $PRESS ]; do
    sleep 0.1
  done
 
  : > $PRESS      # reset tempfile

done

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Tue 12 Mar 2013, 17:47    Post subject:  

SFR wrote:
You mean something like:
1. Looped cursor movement right (coarse) within fullscreen
2. Looped cursor movement down (coarse) within fullscreen
3. Looped cursor movement right (fine) within reduced area
4. Looped cursor movement down (fine) within reduced area
5. Left-click
6. GOTO 1
?

Yes, that's the concept. I hope to try your script after work tonight. I'm hoping to handle everything with a mousebutton only (instead of the pause/break) but getting the cursor movement right is the first major step.

You are redundifying my initial "xdotool mousemove" plan, but that's probably a good thing Smile
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Wed 13 Mar 2013, 13:07    Post subject:  

I think I must be doing something wrong with my manual keybinding method. I can't get the script to respond to the pause key. The end paragraph of my /root/.jwm/jwm-personal looks like this:

Code:

<Key keycode="160">exec:amixer sset Master toggle</Key>
<Key keycode="176">exec:amixer sset Master 1+,1+</Key>
<Key keycode="174">exec:amixer sset Master 1-,1-</Key>
<Key keycode="178">exec:defaultbrowser</Key>
<Key keycode="236">exec:defaultbrowser</Key>
<Key keycode="111">exec:mtpaintsnapshot.sh</Key>
<Key keycode="75">exec:doubleclick_xdotool</Key>
<Key keycode="110">echo true > /tmp/button_press_signal</Key>
</JWM>


I'm running Slacko53 so maybe I do already have xbindkeys as you suggested. I just need to do a bit of research to find out how to drive xbindkeys. I probably should load the gui.

EDIT : I just tried xbindkeys -k and it works so I definitely have xbindkeys. That cmd gave me some info which I am apparently supposed to graft into my /root/.xbindkeysrc file, which now has this:

Code:
# Task manager
"/usr/local/bin/pprocess"
   Control+Alt + Delete
   
#Added by greengeek to allow pause button to work with SFR mousemove script
"echo true > /tmp/button_press_signal"
   m:0x0 + c:110
   Pause
##################################
# End of xbindkeys configuration #
##################################

but still no joy yet.

EDIT : Maybe I need to restart Xserver instead of just jwm each time.

EDIT : Yes! that's what was wrong - I needed to resatrt X.

SFR - This script is fantastic!!! It's giving me really good control over focus and positioning. I think I can use this to really good advantage. Thanks!!
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Thu 14 Mar 2013, 03:36    Post subject:  

Hi SFR: the parameters that I think suit my needs perfectly are:
Code:
STEP_COARSE=2
STEP_FINE=1     
SPEED_COARSE=0.01
SPEED_FINE=0.1


If it is possible I would like the cursor to pause momentarily as it loops horizontally back through X=0 so that it is easier to line the pointer up with the menu button without overshooting (or maybe pause at x=15), and also pause momentarily as it loops vertically through y=10.

My guess is it would need to be something like:

Code:
  # ======
  # COARSE
  # ======
  until [ -s $PRESS ]; do
    X=$(($X+$STEP_COARSE)); [ $X -ge $MAXX ] && X=0
    xdotool mousemove $X $Y
#greengeek mod for pause momentarily at x=15
#if x=15
#sleep 2
#fi
    sleep $SPEED_COARSE
  done
  : > $PRESS
  sleep 0.5
  until [ -s $PRESS ]; do
    Y=$(($Y+$STEP_COARSE)); [ $Y -ge $MAXY ] && Y=10
    xdotool mousemove $X $Y
#greengeek mod for pause momentarily at y=10
#if y=10
#sleep 2
#fi
    sleep $SPEED_COARSE
  done
  : > $PRESS


But of course it's a stab in the dark as usual. Can you help?? (P_l_e_e_e_a_s_e..) Thanks!
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Thu 14 Mar 2013, 04:58    Post subject:  

test post using sfr2
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Thu 14 Mar 2013, 06:28    Post subject:  

Hey Greengeek

Code:
  # ======
  # COARSE
  # ======
  until [ -s $PRESS ]; do
    X=$(($X+$STEP_COARSE)); [ $X -ge $MAXX ] && X=0
    xdotool mousemove $X $Y
    [ $X = 16 ] && sleep 2 || sleep $SPEED_COARSE    # X must be even, since STEP_COARSE=2
  done
  : > $PRESS
  sleep 0.5
  until [ -s $PRESS ]; do
    Y=$(($Y+$STEP_COARSE)); [ $Y -ge $MAXY ] && Y=10
    xdotool mousemove $X $Y
    [ $Y = 10 ] && sleep 2 || sleep $SPEED_COARSE    # Y must be even, since STEP_COARSE=2
  done
  : > $PRESS

However, I just noticed that while Menu (also pull-down menus) is opened, xbindkeys are off for some reason (tried under Compiz & JWM). Confused
Do you have the same problem with this?

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Thu 14 Mar 2013, 10:21    Post subject:  

Yes, same problem here. Still trying to nut out a way around that. Also been seeing a couple of oddities that seem to be interactions between certain open windows. For example sometimes I hit the print scrn key by mistake and the screenshot timer opens up, and I get several mousepointers on screen at once, all doing their own thing (aaaaarrrgggh!).

With regard to the lockout of xbindkeys I thought about the possibility of having a separate script running in the background which waited till it detected a period of 10 or fifteen seconds where there was no mouse or key action, then automatically generated an "arrow down one" keystroke (slowly repeated until the pause break key was hit again). Sorry that this description is not that clear - what I mean is that I found that when I selected something like the "File" tab in a window, and the dropdown menu appeared, I was not able to use the pause key, but WAS able to tap the arrow down key to scroll down through the menu choices. I have it in mind that the pause key then came back active but I'm going to have to confirm that.

In trying to find a way around these issues I did note a couple of times that I got the focus back onto the sfr2 script, and was able to carry on, but had no idea exactly how/why.

In particular I noticed different window interactions depending on whether I started sfr2 by clicking the script icon, or by opening a terminal there and using the ./sfr2 syntax.

EDIT : Also I noticed that behaviours were slightly altered when I was using xvkbd onscreen at the same time. It has it's own "focus" button so that was adding extra confusion to my trials. I can't yet pin down all the symptoms/variations I'm getting.

Lots more testing for me to do.

EDIT : BTW - the delay that you added for low values of X and Y is excellent. Perfect. Well done adjusting for even values. I wonder if I should have gone to step=1 and just doubled the speed? (Maybe the script should always be set for a step size of 1 only, and just use the speed control to get the desired effect...? I'll come back to that thought after further testing).
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1068

PostPosted: Thu 14 Mar 2013, 10:50    Post subject:  

greengeek wrote:
With regard to the lockout of xbindkeys I thought about the possibility of having a separate script running in the background which waited till it detected a period of 10 or fifteen seconds where there was no mouse or key action, then automatically generated an "arrow down one" keystroke (slowly repeated until the pause break key was hit again). Sorry that this description is not that clear - what I mean is that I found that when I selected something like the "File" tab in a window, and the dropdown menu appeared, I was not able to use the pause key, but WAS able to tap the arrow down key to scroll down through the menu choices. I have it in mind that the pause key then came back active but I'm going to have to confirm that.

I think I know what you mean, but the problem is that (at least in my tests), Pause key stays unresponsive, no matter if I tap arrow down key to scroll through menu options or not...

More oddities: xbindkeys works fine when I have a pull-down menu opened in Firefox, but not, eg. DeaDBeeF, Geany...

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
greengeek

Joined: 20 Jul 2010
Posts: 2542
Location: New Zealand

PostPosted: Thu 14 Mar 2013, 11:08    Post subject:  

I wonder if the relative cpu priorities of each process could have such an effect?
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 6 [84 Posts]   Goto page: 1, 2, 3, 4, 5, 6 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Puppy Projects
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1494s ][ Queries: 13 (0.0133s) ][ GZIP on ]