 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Icarus
Joined: 24 Nov 2005 Posts: 440
|
Posted: Mon Jun 02, 2008 5:56 pm Post subject: No Mouse Today! - A Numpad Mouse Replacement |
|
|
No Mouse Today! v0.15
Wanted to do my own variation for a mouse replacement, using the magnificent numpad.
I checked the help page (search for "numpad") and there is a huge script there to do that (>700 lines) and it seemed to be a little too complicated to my taste, and did not work on my computer (dont know if its because it is too old, didnt try to fix it)
This version supports inertia for the mouse movement, for a more convenient use.
So, here is my version.
| Code: |
;-------------------------------------------------------------------------------
; No Mouse Today! 0.15
; A Numpad Mouse Replacement (for days without a mouse...)
;-------------------------------------------------------------------------------
;
; Disable Numlock to Activate
; +------------+------------+------------+------------+
; | Numlock | / (Toggle) | * | - |
; | Off | Drag | | Center Win |
; +------------+------------+------------+------------+
; | 7 | 8 | 9 | + |
; | Wheel Up | Up | Navgat Fwd | Right Clik |
; +------------+------------+------------+ |
; | 4 | 5 | 6 | |
; | Left | Click | Right | |
; +------------+------------+------------+------------+
; | 1 | 2 | 3 | Enter |
; | Wheel Down | Down | Navgat Bck | Dbl Click |
; +------------+------------+------------+ |
; | 0 (Hold) | . | |
; | Constant Move Speed | | |
; +-------------------------+------------+------------+
; Hold down Shift while moving for one pixel movement
; Hold down Alt for 2468 to act like mouse wheel scroll (4 directions)
; Pressing two movement keys together will move diagonally
; Pressing Ctrl, Alt or Shift while clicking or mousewheeling works the same
; as with a normal mouse
;
;-------------------------------------------------------------------------------
#SingleInstance Force
#HotkeyInterval 1000
#MaxHotkeysPerInterval 1000
SendMode Play
; --- CONFIGURATION ------------------------------------------------------------
ConstantSpeed := 10 ; Pixels to move when Numpad0 is held down
MinSpeed := 1 ; Pixels to move at the beginning of the movement
MaxSpeed := 20 ; Pixels to move at the fastest inertia
Inertia := 0.2 ; How fast should we increase speed (higher=faster, 0=none)
InertiaDelay := 10 ; Number of movements to wait before starting inertia
WheelSleep := 80 ; MSeconds to sleep between wheel sends
; --- CONFIATION ------------------------------------------------------------
Menu Tray, NoStandard
Menu Tray, Add, Exit No Mouse Today!, Exit
Return
MouseMove:
; This routine handles the 2468 keys: Mouse moves, or mouse wheel emulation
ControlGetFocus, fcontrol, A
Counter := 0
Loop {
If( GetKeyState( "Alt", "P" ) ) { ; Wheel Emulation through Ctrl+2468
WX := ( GetKeyState( "NumpadRight", "P" ) ? 1 : GetKeyState( "NumpadLeft", "P" ) ? 0 : -1 )
WY := ( GetKeyState( "NumpadDown" , "P" ) ? "WheelDown" : GetKeyState( "NumpadUp", "P" ) ? "WheelUp" : -1 )
If( WX<>-1 )
SendMessage, 0x114, %WX%, 0, %fcontrol%, A ; 0x114 is WM_HSCROLL and the 0 after it is SB_LINERIGHT.
If( WY<>-1 )
SendInput {%WY%}
Sleep %WheelSleep%
}
Else { ; Mouse moves
Speed := ( GetKeyState( "NumpadIns", "P" ) ? ConstantSpeed : Counter>InertiaDelay ? MinSpeed+(Counter-InertiaDelay)*Inertia : MinSpeed )
Speed := Speed > MaxSpeed ? MaxSpeed : Speed
Counter++
X := Speed * ( GetKeyState( "NumpadRight", "P" ) ? 1 : GetKeyState( "NumpadLeft", "P" ) ? -1 : 0 )
Y := Speed * ( GetKeyState( "NumpadDown" , "P" ) ? 1 : GetKeyState( "NumpadUp", "P" ) ? -1 : 0 )
If( X or Y ) {
MouseMove %X%,%Y%,,R
If( GetKeyState( "Shift" , "P" ) )
Break
}
Else
Break
}
}
Return
MouseWheel:
; This routine handles the 17 keys: mouse wheel
Loop {
WUp := GetKeyState( "NumpadHome", "P" )
WDn := GetKeyState( "NumpadEnd", "P" )
If( WUp ) or ( WDn ) {
SendInput % GetModifier() . ( WUp ? "{WheelUp}" : "{WheelDown}" )
Sleep %WheelSleep%
}
Else
Break
}
Return
GetModifier() {
Return GetKeyState( "Ctrl", "P" ) ? "^" : GetKeyState( "Alt", "P" ) ? "!" : GetKeyState( "Shift", "P" ) ? "+" : ""
}
Exit:
ExitApp
Return
; --- KEY MAPPINGS -------------------------------------------------------------
; Mouse Moves
*NumpadRight::
*NumpadDown::
*NumpadUp::
*NumpadLeft::
NumpadIns::Gosub MouseMove
; Mouse Clicks
*NumpadClear::SendInput % GetModifier() . "{Click}"
*NumpadPgUp::SendInput {XButton2}
*NumpadPgDn::SendInput {XButton1}
$*NumpadEnter::
If( Not GetKeyState( "Numlock", "T" ) )
Click 2
Else
SendInput {NumpadEnter}
Return
$*NumpadAdd::
If( Not GetKeyState( "Numlock", "T" ) )
SendInput % GetModifier() . "{RButton}"
Else
SendInput {NumpadAdd}
Return
$*NumpadDiv::
If( Not GetKeyState( "Numlock", "T" ) ) {
SendInput % "{LButton " . ( _Drag ? "Up}" : "Down}" )
_Drag := Not _Drag
}
Else
SendInput {NumpadDiv}
Return
; Special Functions
$NumpadSub::
If( Not GetKeyState( "Numlock", "T" ) ) {
WinGetPos X,Y,W,H,A
MouseMove % W/2, % H/2
}
Else
SendInput {NumpadSub}
Return
; Mouse Wheel
*NumpadHome::
*NumpadEnd::Gosub MouseWheel
; Stuff
^ESC::ExitApp
|
This is an older version, with no inertia for those who still like it:
| Code: | ;-------------------------------------------------------------------------------
; No Mouse Today! 0.13
; A Numpad Mouse Replacement (for days without a mouse...)
;-------------------------------------------------------------------------------
;
; Disable Numlock to Activate
; +------------+------------+------------+------------+
; | Numlock | / (Toggle) | * | - |
; | Off | Drag | | Center Win |
; +------------+------------+------------+------------+
; | 7 | 8 | 9 | + |
; | Wheel Up | Up | Navgat Fwd | Right Clik |
; +------------+------------+------------+ |
; | 4 | 5 | 6 | |
; | Left | Click | Right | |
; +------------+------------+------------+------------+
; | 1 | 2 | 3 | Enter |
; | Wheel Down | Down | Navgat Bck | Dbl Click |
; +------------+------------+------------+ |
; | 0 (Hold) | . (Hold) | |
; | Fast Move | Slow Move | |
; +-------------------------+------------+------------+
; Hold down Shift while moving for one pixel movement
; Hold down Alt for 2468 to act like mouse wheel scroll (4 directions)
; Pressing two movement keys together will move diagonally
; Pressing Ctrl, Alt or Shift while clicking or mousewheeling works the same
; as with a normal mouse
;
;-------------------------------------------------------------------------------
#SingleInstance Force
#HotkeyInterval 1000
#MaxHotkeysPerInterval 1000
SendMode Play
; --- CONFIGURATION ------------------------------------------------------------
SpeedNormal := 3 ; Pixels to move on normal movement
SpeedZero := 6 ; Pixels to move when Numpad0 is held down
SpeedDot := 1 ; Pixels to move when NumpadDot is held down
WheelSleep := 80 ; MSeconds to sleep between wheel sends
; --- CONFIGURATION ------------------------------------------------------------
Return
MouseMove:
; This routine handles the 2468 keys: Mouse moves, or mouse wheel emulation
ControlGetFocus, fcontrol, A
Loop {
If( GetKeyState( "Alt", "P" ) ) { ; Wheel Emulation through Ctrl+2468
WX := ( GetKeyState( "NumpadRight", "P" ) ? 1 : GetKeyState( "NumpadLeft", "P" ) ? 0 : -1 )
WY := ( GetKeyState( "NumpadDown" , "P" ) ? "WheelDown" : GetKeyState( "NumpadUp", "P" ) ? "WheelUp" : -1 )
If( WX<>-1 )
SendMessage, 0x114, %WX%, 0, %fcontrol%, A ; 0x114 is WM_HSCROLL and the 0 after it is SB_LINERIGHT.
If( WY<>-1 )
SendInput {%WY%}
Sleep %WheelSleep%
}
Else { ; Mouse moves
Speed := GetKeyState( "NumpadIns", "P" ) ? SpeedZero : GetKeyState( "NumpadDel", "P" ) ? SpeedDot : GetKeyState( "Shift" , "P" ) ? 1 : SpeedNormal
X := Speed * ( GetKeyState( "NumpadRight", "P" ) ? 1 : GetKeyState( "NumpadLeft", "P" ) ? -1 : 0 )
Y := Speed * ( GetKeyState( "NumpadDown" , "P" ) ? 1 : GetKeyState( "NumpadUp", "P" ) ? -1 : 0 )
If( X or Y ) {
MouseMove %X%,%Y%,,R
If( GetKeyState( "Shift" , "P" ) )
Break
}
Else
Break
}
}
Return
MouseWheel:
; This routine handles the 17 keys: mouse wheel
Loop {
WUp := GetKeyState( "NumpadHome", "P" )
WDn := GetKeyState( "NumpadEnd", "P" )
If( WUp ) or ( WDn ) {
SendInput % GetModifier() . ( WUp ? "{WheelUp}" : "{WheelDown}" )
Sleep %WheelSleep%
}
Else
Break
}
Return
GetModifier() {
Return GetKeyState( "Ctrl", "P" ) ? "^" : GetKeyState( "Alt", "P" ) ? "!" : GetKeyState( "Shift", "P" ) ? "+" : ""
}
; --- KEY MAPPINGS -------------------------------------------------------------
; Mouse Moves
*NumpadRight::
*NumpadDown::
*NumpadUp::
*NumpadLeft::
NumpadIns::
NumpadDel::Gosub MouseMove
; Mouse Clicks
*NumpadClear::SendInput % GetModifier() . "{Click}"
*NumpadPgUp::SendInput {XButton2}
*NumpadPgDn::SendInput {XButton1}
$*NumpadEnter::
If( Not GetKeyState( "Numlock", "T" ) )
Click 2
Else
SendInput {NumpadEnter}
Return
$*NumpadAdd::
If( Not GetKeyState( "Numlock", "T" ) )
SendInput % GetModifier() . "{RButton}"
Else
SendInput {NumpadAdd}
Return
$*NumpadDiv::
If( Not GetKeyState( "Numlock", "T" ) ) {
SendInput % "{LButton " . ( _Drag ? "Up}" : "Down}" )
_Drag := Not _Drag
}
Else
SendInput {NumpadDiv}
Return
; Special Functions
$NumpadSub::
If( Not GetKeyState( "Numlock", "T" ) ) {
WinGetPos X,Y,W,H,A
MouseMove % W/2, % H/2
}
Else
SendInput {NumpadSub}
Return
; Mouse Wheel
*NumpadHome::
*NumpadEnd::Gosub MouseWheel
; Stuff
^ESC::ExitApp
|
Last edited by Icarus on Mon Jun 16, 2008 8:59 am; edited 6 times in total |
|
| Back to top |
|
 |
RobOtter
Joined: 30 Jan 2005 Posts: 125 Location: Darmstadt, Germany
|
Posted: Tue Jun 03, 2008 7:54 am Post subject: |
|
|
Hi Icarus, thanks for this little gem!
I tried it and it comes quite handy for me. I really like the idea of letting a mouse button held down - this could really help people having trouble pressing several keys at a time and is very comfortable as well for others.
Since there are some keys unused until now, how about adding a horizontal scroll function (maybe on Num-9 and Num-3)?
And on key Num--, a "Very Slow Move" (exactly 1 Pixel at a time) would be good, too (would help me position the cursor in my favorite graphics program).
Greetings,
Rob |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 440
|
Posted: Tue Jun 03, 2008 8:06 am Post subject: |
|
|
Is there a autohotkey scroll right/left? I am assuming you mean the mouse wheel scroll, and not keyboard arrows yes?
And for the NumpadMinus, you mean that when held down, the presses on the 2468 keys will not be continuous, but will require repetitive presses to move one pixel at a time. yes again?
Thats all easy, in fact I have already made some minor changes in the script, to ignore presses (for example on the mult and div keys) when numlock is off.
Will post it later, perhaps with your changes.
EDIT:
Some of the changes I think make it much more comfortable:
5 will be click
+ will be right click
Enter will be dbl click
/ will be drag (toggle)
* unmapped
EDIT2:
Posted a new version with the above changes and the one pixel move |
|
| Back to top |
|
 |
RobOtter
Joined: 30 Jan 2005 Posts: 125 Location: Darmstadt, Germany
|
Posted: Tue Jun 03, 2008 9:37 am Post subject: |
|
|
| Icarus wrote: | | Is there a autohotkey scroll right/left? I am assuming you mean the mouse wheel scroll, and not keyboard arrows yes? |
You΄re right, that΄s what I΄ve meant. Although there is no native support in AHK for horizontal scrolling, I΄ve found a thread (http://www.autohotkey.com/forum/viewtopic.php?t=31152) using a SendMessage command doing that (WM_HSCROLL).
| Icarus wrote: | | And for the NumpadMinus, you mean that when held down, the presses on the 2468 keys will not be continuous, but will require repetitive presses to move one pixel at a time. yes again? |
It may be done that way, but slowing down the mouse movement in such a way that moving one pixel is possible with a short key press would be sufficient (keeping the continuous movement like with the other modifiers).
| Icarus wrote: | EDIT:
Some of the changes I think make it much more comfortable:
5 will be click
+ will be right click
Enter will be dbl click
/ will be drag (toggle)
* unmapped
EDIT2:
Posted a new version with the above changes and the one pixel move |
Thanks for the changes. In the previous version, there was a bug (Num-Enter (=Right Click) worked even when Numpad was switched on) which seems to be killed now  |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 440
|
Posted: Tue Jun 03, 2008 11:21 am Post subject: |
|
|
Yes, I found how to do it, but forgot to mention.
9 and 3 are already used - navigate forward and back (XButton1 and 2)
So, I think I will keep vertical scroll out, also since it can usually be done by the normal arrow keys.
If you insist, you can of course do it yourself, or I can make a special version just for you if you need my help.
I would like to remove the minus as a one pixel mover, and instead make it Shift (holding down the minus key is not intuitive and inconvenient)
And I want to do the minus so it will center on screen, or move to the center of the focused window, or something like that.
The star is a key I would like to keep unmapped (for completely selfish reasons - I am using it for another script of mine which activates an input field where I enter a number and it executes stuff... )
EDIT:
Better idea:
Holding down the Ctrl key while moving (2468) will emulate mouse wheel in its four directions. Good no? |
|
| Back to top |
|
 |
RobOtter
Joined: 30 Jan 2005 Posts: 125 Location: Darmstadt, Germany
|
Posted: Tue Jun 03, 2008 11:41 am Post subject: |
|
|
| Icarus wrote: | | 9 and 3 are already used - navigate forward and back (XButton1 and 2) |
Personally, I dislike this behavior since it has nothing to do with mouse movement. But feel free to do whatever you like with your script
| Icarus wrote: | | I would like to remove the minus as a one pixel mover, and instead make it Shift (holding down the minus key is not intuitive and inconvenient) |
I feel sorry for loosing the 1pm (one-pixel-mover ) and do not see the advantage of having a third shift key - but of course, it is all at your will.
I will keep the current source code and will create a special-for-Rob version based on your code - I believe this is what posting a script here is intended for...
| Icarus wrote: | | And I want to do the minus so it will center on screen, or move to the center of the focused window, or something like that. |
That΄s a good idea - helps moving quicker!
| Icarus wrote: | EDIT:
Better idea:
Holding down the Ctrl key while moving (2468) will emulate mouse wheel in its four directions. Good no? |
VERY good! It is quite intuitive and keeps 71 free for other purposes. |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 440
|
Posted: Tue Jun 03, 2008 11:53 am Post subject: |
|
|
No no, you misunderstood me:
I will map the Shift key to be the one that forces 1pm, instead of the minus key. So it will free the minus key, and you will still have the 1pm functionality.
Also, I will keep the 1 and 7 as the wheel, but in order to add your functionality for vertical scroll, I will add Ctrl+4 and Ctrl+6 as vertical scroll (and for completeness, also the Ctrl+8 and Ctrl+2 will do scrolling, horizontal)
I use the XBUtton 1 and 2 a lot to navigate back and forth, in the browser or in windows explorer.
So, dont worry, you will have all your functionality in tact.
You can disable 9 and 3 if you hate them that much of course. |
|
| Back to top |
|
 |
RobOtter
Joined: 30 Jan 2005 Posts: 125 Location: Darmstadt, Germany
|
Posted: Tue Jun 03, 2008 2:37 pm Post subject: |
|
|
| Thanks to allow for my wishes - I΄m looking forward to the next version! |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 440
|
Posted: Tue Jun 03, 2008 4:48 pm Post subject: |
|
|
Ok, posted the new versions on post 1.
I used Alt as a mousewheel modifier (Alt+2468) instead of Ctrl, since Ctrl is usually used for zooming, and I didnt want to mess with it.
Also, I was thinking about your graphic applications, so diagonal wheeling is also made possible (Alt+2+6 will do diagonal wheel right+down)
Minus centers the mouse on the active window. |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 440
|
Posted: Wed Jun 04, 2008 6:42 am Post subject: |
|
|
| Posted 0.13 with some fixes |
|
| Back to top |
|
 |
tidbit
Joined: 10 Mar 2008 Posts: 90
|
Posted: Wed Jun 04, 2008 10:59 pm Post subject: |
|
|
very nice.
I like to use it with my mouse tis a good team _________________ rawr. be very affraid |
|
| Back to top |
|
 |
Icarus
Joined: 24 Nov 2005 Posts: 440
|
Posted: Mon Jun 16, 2008 9:01 am Post subject: |
|
|
Posted a new version (0.15) with mouse movement inertia.
Now the speed will increase gradually (configurable).
Numpad Dot was removed
Numpad 0 will now be used to enforce Constant Speed (no inertia) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|