AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

keyboard as mouse

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ratsrcute



Joined: 28 May 2006
Posts: 44

PostPosted: Mon Dec 14, 2009 10:49 pm    Post subject: keyboard as mouse Reply with quote

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
Back to top
View user's profile Send private message
ratsrcute



Joined: 28 May 2006
Posts: 44

PostPosted: Tue Dec 15, 2009 12:40 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
System Monitor



Joined: 09 Mar 2007
Posts: 509
Location: Unknown

PostPosted: Tue Dec 15, 2009 1:34 am    Post subject: Reply with quote

http://www.autohotkey.com/docs/scripts/NumpadMouse.htm
Back to top
View user's profile Send private message Visit poster's website
ratsrcute



Joined: 28 May 2006
Posts: 44

PostPosted: Tue Dec 15, 2009 3:00 am    Post subject: Reply with quote

System Monitor wrote:
http://www.autohotkey.com/docs/scripts/NumpadMouse.htm


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.
Back to top
View user's profile Send private message
None



Joined: 28 Nov 2009
Posts: 3086

PostPosted: Tue Dec 15, 2009 5:33 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
ratsrcute



Joined: 28 May 2006
Posts: 44

PostPosted: Tue Dec 15, 2009 8:20 pm    Post subject: Reply with quote

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



Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group