AutoHotkey Community

It is currently May 27th, 2012, 12:34 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: keyboard as mouse
PostPosted: December 14th, 2009, 11:49 pm 
Offline

Joined: May 28th, 2006, 1:48 am
Posts: 46
Hello, I know there are a ton of existing scripts using the keyboard as a mouse, so I hope someone can help me find my way. I have some specific requirements that are a little different than the existing scripts I can find.

I want to use j, k, l, and i to move the mouse. Obviously this will require a "mouse mode". I already wrote a function to toggle in and out of mouse mode via two quick CapsLock presses. This is my favorite way to toggle in and out of special modes.

I also want to implement different movement speeds by a particular mechanism.

For example, to go left at normal speed press and hold J.

To go faster, press the shift key along with J. I would like changes in the Shift state to register even while J is held down.

To go slow, press the ctrl key along with J.

To go one step, press and release J. To be sure that single steps are registered as single steps, holding J for less than 100 ms indicates you want a single step. After 100 ms, it will start to move continuously.

I have some experience writing AHK scripts, but some of the unfamiliar twists in this particular script would be the idea of registering Shift up and down while J is held, and timing the 100 ms delay before repeat.

Thanks,
Mike


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 1:40 am 
Offline

Joined: May 28th, 2006, 1:48 am
Posts: 46
Before anyone does too much work on this, I managed to figure out a lot of it. I'll post my script later today or tomorrow. I may have gotten it to work, but I'm sure most people here can do it more gracefully or compactly than me.
Thanks,
Mike


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 2:34 am 
Offline

Joined: March 9th, 2007, 2:47 am
Posts: 509
Location: Unknown
http://www.autohotkey.com/docs/scripts/NumpadMouse.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 4:00 am 
Offline

Joined: May 28th, 2006, 1:48 am
Posts: 46
System Monitor wrote:


I saw that one, but I don't have a number pad, and I dislike the concept of acceleration as a way of controlling speed. Normally I would try to modify the script but it is huge, complicated, and not very close to what I want (at least as best I understand what it does).

I'll post my script in a little bit.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 6:33 am 
Offline

Joined: November 28th, 2009, 4:45 am
Posts: 3089
Something like This
Code:
Step:=8
*j::Settimer Jloop, 15
*j up::Settimer Jloop, Off

Jloop:
    Mult1:=GetKeyState("Shift")
    Mult2:=GetKeyState("Ctrl")
    MouseGetPos, VarX, VarY
    MouseMove, (VarX-(Step-(Step*Mult2/2)+Step*Mult1*2)),VarY
Return

Does every thing except 100ms delay

Edit:
I thought a a way to make it pause
Code:
Step:=8
Sleep:=100
*j::Settimer Jloop, 15
*j up::
Settimer Jloop, Off
Sleep:=100
Return

Jloop:
    Mult1:=GetKeyState("Shift")
    Mult2:=GetKeyState("Ctrl")
    MouseGetPos, VarX, VarY
    MouseMove, (VarX-(Step-(Step*Mult2/2)+Step*Mult1*2)),VarY
    Sleep %Sleep%
    Sleep:=0
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2009, 9:20 pm 
Offline

Joined: May 28th, 2006, 1:48 am
Posts: 46
Thanks for the pointers.

Using some of your ideas, here's how I ended up doing it.
Code:
;----------------------------------------------------------------------
;; Two quick capslock to turn on mouse mode
$CapsLock::

   if ( GetKeyState("CapsLock", "T") )
   {
        newstate = off
   }
   else
   {   
        newstate = on
   }
   SetCapsLockState, %newstate%
   
   if ( A_PriorHotkey != A_ThisHotKey || A_TimeSincePriorHotkey > 400 )
   {
      Return
   }
   
   ;; At this point we know a double-capslock has happened.
   ;; This will start mouse mode. A return value of
   ;; a 1 means that we should start the menu. 0 means return immediately.

   gosub MouseModeStart
Return

MouseModeStart:
   slowStep := 1
   mediumStep := 9
   fastStep := 25
   preDelayTime := 90
   interDelayTime := 40

   CoordMode, ToolTip
   t := "M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M  M "
   tt := t . t . t . t . t
   ToolTip, %tt%, 0, 0

   Hotkey, *j, leftMouse, On
   Hotkey, *l, rightMouse, On
   Hotkey, *k, downMouse, On
   Hotkey, *i, upMouse, On

   Hotkey, *v, exitMouse, On
   Hotkey, *f, fMouse, On
   Hotkey, *d, dMouse, On
   Hotkey, *g, gMouse, On
   Hotkey, *t, tMouse, On
   Hotkey, *Enter, goToMenu, On
Return

exitMouse:
   ToolTip
   Hotkey, *j, Off
   Hotkey, *l, Off
   Hotkey, *k, off
   Hotkey, *i, Off

   Hotkey, *v, Off
   Hotkey, *f, Off
   Hotkey, *d, Off
   Hotkey, *g, Off
   Hotkey, *t, Off
   Hotkey, *Enter, Off
Return

rightMouse:
   gx := 1
   gy := 0
   gkey = l
   Gosub, generalMouse
Return

leftMouse:
   gx := -1
   gy := 0
   gkey = j
   Gosub, generalMouse
Return

upMouse:
   gx := 0
   gy := -1
   gkey = i
   Gosub, generalMouse
Return

downMouse:
   gx := 0
   gy := 1
   gkey = k
   Gosub, generalMouse
Return


generalMouse:
   GoSub generalMouseMove
   Sleep, %preDelayTime%
   SetTimer, generalMouseMove, %interDelayTime%
   KeyWait, %gkey%
   SetTimer, generalMouseMove, Off
Return

generalMouseMove:
   s := GetKeyState("shift")
   c := GetKeyState("ctrl")
   factor := mediumStep
   if s
      factor := fastStep
   if c
      factor := slowStep
   x := factor * gx
   y := factor * gy
   MouseMove, %x%, %y%, 0, R
Return

goToMenu:
   gosub exitMouse
   gosub startMenu
Return

fMouse:
  Click, down
  keywait,f
  Click, up
Return

dMouse:
  Click, right
Return

gMouse:
  Click, WheelDown
Return

tMouse:
  Click, WheelUp
Return





Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], iDrug, Leef_me, Ohnitiel, rjgatito, Yahoo [Bot] and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group