thanks for the reply and feedback! i'm glad at least someone tried/liked it...
(i'm also not left handed, but there is a lefty at my work and i added a second mouse to her computer today, now everyone can use either mouse!)
its also tested working on XPSP3 and Vista... the primary issue to work out now is if synaptics drivers are messing with the settings (common on touchpads for laptops)
i'm happy to help out when i can, but i'm not interested a new day job of making scripts for people; i'm loving AHK tho and have been making a full-scale application with it to monitor CNC machine's, reporting status, controlling lights, update webpage, etc...
As far as keyboards, i created this script from the skeleton of a dirty script i wrote to detect keys from a usb numpad, seperate from keys on the normal keyboard numpad (both detected as HID devices), which is working but there are issues... i read those threads you linked and i see there is a desire for it so i'll clean up that script,
but i can foresee an issue, which is the equivalent to what happens if you use this script with one mouse moving but click with the second... this manner of differentiation is "modal" but really you want simultaneous knowledge of the key and the device... not really sure but i'll see how it can be adapted... if the key is doing something in your app, and being blocked from normal operation (on both keyboards) then it would be easy
------------
Edit:a quick mod to EitherMouse yielded EitherKBD, which will [
except for the first key pressed on a keyboard after a different one is used] apply a hotkey to one keyboard and not the other
After thinking about it, i think this could be used to solve a lot of the requests for keyboard differentiation, with better logic to apply the hDevice before the hotkey effect is acted out...
;=== EitherKbd
;=== made by gwarble, aug09
;=== keyboard differention first attempt, hotkeys 1 and A
Version = 0.1
#SingleInstance, Force
#NoEnv
#NoTrayIcon
Critical
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%
OnExit, ExitEitherMouse
;=== uses exe's icons, compiled or not, and default windows icons if no exe is available
If A_IsCompiled
IconFile := A_ScriptName
Else
IfExist, EitherMouse.exe
IconFile := "EitherMouse.exe"
Else
IconFile := "main.cpl" ;=== icon used if .exe/ahksc.bin is not available for good icons
Menu, Tray, NoStandard
Menu, Tray, Icon, % IconFile, 1
Menu, Tray, Icon
;== create [fake] tray menu; WM_NotifyIcon makes either button act the same on the tray icon: single click either button for menu, double for about window
Menu, Tray1, Add, EitherMouse, AboutEitherMouse
Menu, Tray1, Default, EitherMouse
Menu, Tray1, Add
Menu, Options, Add, Delete Assignments..., ClearReload
Menu, Options, Add
Menu, Options, Add, Save Assignments..., SaveAssignments
Menu, Options, Add
Menu, Options, Add, Create Startup Shortcut, CreateStartup
Menu, Options, Add, Install to Program Files, InstallEitherMouse
Menu, Options, Add
Menu, Options, Add, Swap Windows Setting, SwapWindows
Menu, Options, Add, Mouse Settings..., MouseSettings
Menu, Tray1, Add, Options, :Options
Menu, Tray1, Add, Restart..., Reload
Menu, Tray1, Add
Menu, Tray1, Add, Exit, ExitApp
Menu, Tray, Tip, % " `n EitherMouse " Version " `n "
OnMessage(0x404, "AHK_NOTIFYICON")
IniRead, FirstMouse, EitherMouse.ini, Assignments, First Mouse , % " "
If FirstMouse > 0
{
LastDevice := FirstMouse
IniRead, SecondMouse, EitherMouse.ini, Assignments, Second Mouse , % " "
IniRead, Swapped, EitherMouse.ini, Assignments, Swapped , 0
FirstIcon := !Swapped ? 1 : 2
SecondIcon := Swapped ? 1 : 2
GoSub, StartMonitor
TrayTip, EitherMouse %Version%, Settings loaded successfully!, , 16
SetTimer, TrayTip, -3000
Return
}
;=== read registry setting for default windows button configuration
RegRead, Swapped, HKEY_CURRENT_USER, Control Panel\Mouse, SwapMouseButtons
If !Swapped
{
SwappedDesc = right
SwappedDesc2 = left
FirstIcon = 1
SecondIcon = 2
}
Else
{
SwappedDesc = left
SwappedDesc2 = right
FirstIcon = 2
SecondIcon = 1
}
;Menu, Tray, Icon, % IconFile, % FirstIcon
TrayTip, EitherMouse %Version%, Initializing...`n`nMove %SwappedDesc% mouse first!, , 16
Gui, 1:-Caption +Border +AlwaysOnTop +ToolWindow
Gui 1:+LastFound
Gui, 1:Color, White
If !Swapped
{
Gui, 1:Add, Picture, x32 y55 w32 h32 Icon1 vGuiPicL, % "main.cpl"
Gui, 1:Add, Picture, x64 y55 w32 h32 Icon1 vGuiPicR, % IconFile
}
Else
{
Gui, 1:Add, Picture, x32 y55 w32 h32 Icon2 vGuiPicL, % IconFile
Gui, 1:Add, Picture, x64 y55 w32 h32 Icon1 vGuiPicR, % "main.cpl"
}
Gui, 1:Font, s12 w600 cBlack
Gui, 1:Add, Text, x5 y5 w118 h30 Center vGuiTitle, EitherMouse
Gui, 1:Font, s10 w100
Gui, 1:Add, Text, x5 y25 w118 h20 Center BackgroundTrans vGuiTitle2, %Version%
Gui, 1:Add, Text, x5 y100 w118 h40 Center BackgroundTrans vGuiText, Move the %SwappedDesc%`nmouse first
Gui, 2:-Caption +Border +AlwaysOnTop +ToolWindow +LabelBackground +E0x20
Gui 2:+LastFound
Gui, 2:Color, Black
WinSet, Transparent, 135
WinSet, Region, 0-0 w276 h296 R27-27
Gui, 2:Show, w276 h296, EitherMouse Background
Gui, 1:Show, w128 h148, EitherMouse %Version%
SetTimer, FlashIcon, 400
;Return
StartMonitor:
DetectHiddenWindows, On
Process, Exist
hwnd := WinExist("ahk_class AutoHotkey ahk_pid " ErrorLevel)
DetectHiddenWindows, Off
Usage = 6 ; Usage=6:kbd 2:mouse
UsagePage = 1
VarSetCapacity(dev, 12, 0)
NumPut(UsagePage, dev, 0, "UShort")
NumPut(Usage, dev, 2, "UShort")
NumPut(0x100, dev, 4)
NumPut(hwnd, dev, 8)
ret := DllCall("RegisterRawInputDevices"
, "uint", &dev ; pRawInputDevices (pointer to an array of RAWINPUTDEVICE)
, "uint", 1 ; uiNumDevices
, "uint", 12) ; cbSize (size of a RAWINPUTDEVICE structure)
If (ErrorLevel or !ret)
{
GoSub, GuiClose
MsgBox, , EitherMouse %Version%, Registering devices failed.`n`nExiting..., 5
ExitApp
}
If !Swapped
{
Hotkey, $1, LButton, Off
Hotkey, $A, RButton, Off
}
Else
{
Hotkey, $1, RButton, Off
Hotkey, $A, LButton, Off
}
OnMessage(0xFF, "WM_INPUT")
Return
;=== flashes icon until first mouse is assigned
FlashIcon:
If !FlashIcon
If (FirstMouse = "")
Menu, Tray, Icon, % IconFile, % FirstIcon
Else
Menu, Tray, Icon, % IconFile, % SecondIcon
Else
Menu, Tray, Icon, % "main.cpl", 1
FlashIcon := !FlashIcon
Return
SwitchMouseButtons:
If (LastDevice = "")
{
SetTimer, FlashIcon, 250
FirstMouse := jhDevice
LastDevice := jhDevice
Menu, Tray, Icon, % IconFile, % FirstIcon
TrayTip, EitherMouse %Version%, Initializing...`n`nNow move the %SwappedDesc2% mouse!, , 16
Gui 2:+LastFound
Winset, AlwaysOnTop, Off
Gui 1:+LastFound
Winset, AlwaysOnTop, Off
GuiControl, 1:, GuiText, % "Now move the`n" SwappedDesc2 " mouse"
If !Swapped
{
GuiControl, 1:, GuiPicL, % "*icon2 " IconFile
GuiControl, 1:, GuiPicR, % "main.cpl"
}
Else
{
GuiControl, 1:, GuiPicL, % "main.cpl"
GuiControl, 1:, GuiPicR, % "*icon1 " IconFile
}
SetTimer, GuiClose, -5000
Return
}
If (LastDevice = jhDevice or jhDevice = 0)
Return
If (SecondMouse = "")
{
SetTimer, FlashIcon, Off
SecondMouse := jhDevice
If GuiClosed
{
IfNotExist, EitherMouse.ini
TrayTip, EitherMouse %Version%, Both mice assigned!!!`n`nSave settings?..., 3, 16
}
Else
TrayTip
GuiControl, 1:, GuiPicL, % "main.cpl" ;"*icon2 " IconFile
GuiControl, 1:, GuiPicR, % "main.cpl" ;"*icon1 " IconFile
GuiControl, 1:, GuiTitle, % "Success!"
GuiControl, 1:, GuiTitle2, % "Both mice assigned"
GuiControl, 1:Move, GuiText, y80
GuiControl, 1:, GuiText, % " First Second`n"FirstMouse " " SecondMouse
Gui, 1:Add, Button, x15 y118 w44 h20 cSilver gSaveAssignments, Save
Gui, 1:Add, Button, x69 y118 w44 h20 cSilver gClearReload, Retry
SetTimer, GuiClose, -5000
;SetTimer, SaveAssignments, -1000
}
LastDevice := jhDevice
SetMode:
If (jhDevice = FirstMouse)
{
Hotkey, $1, Off
Hotkey, $A, Off
;GoSub, SwapReg
Menu, Tray, Icon, % IconFile, % FirstIcon
}
Else
{
Hotkey, $1, On
Hotkey, $A, On
;GoSub, SwapReg
Menu, Tray, Icon, % IconFile, % SecondIcon
}
Return
WM_INPUT(wParam, lParam)
{
Critical
global jhDevice
VarSetCapacity(raw, 40, 0)
ret := DllCall("GetRawInputData", "uint", lParam, "uint", 0x10000003
, "uint", &raw, "uint*", 40, "uint", 16, "int")
If (ErrorLevel or ret = -1)
Return 0
hDevice := NumGet(raw, 8)
jhDevice := hDevice
GoSub, SwitchMouseButtons
Return 1
}
;=== proper handling of switched mouse buttons, thanks to Chris [of ahk]
LButton:
MsgBox, 1
Return
RButton:
MsgBox, A
Return
AHK_NOTIFYICON(wParam, lParam) {
If (lParam = 0x206 or lParam = 0x203) ; WM_RBUTTONDBLCLK or L
{
SetTimer, ShowMenu, off
SetTimer, AboutEitherMouse, -100
}
Else If (lParam = 0x202 or lParam = 0x205 ) ; WM_LBUTTONUP or R
SetTimer, ShowMenu, -250
}
GuiClose:
GuiClosed := 1
Gui, 1:Destroy
Gui, 2:Destroy
SetTimer, TrayTip, -1500
SetTimer, FlashIcon, Off
SetTimer, SetMode, -100
Return
Gui2Close:
Gui, 2:Destroy
Return
ShowMenu:
Menu, Tray1, Show
Return
TrayTip:
TrayTip ;destroyed
Return
^+F12::
ClearReload:
FileDelete, EitherMouse.ini
^F12::
Reload:
Reload
DoNothing:
Return
SwapButtons:
FirstMouse := SecondMouse
SecondMouse := ""
Return
SwapWindows:
Run control mouse
WinWait Mouse Properties
WinActivate
ControlGetText, OutputVar
If OutputVar = Button Configuration
Send {space}{Enter}
Swapped := !Swapped
Return
MouseSettings:
Run control mouse
ExitApp
Return
CreateStartup:
IfNotExist, %A_Startup%\%A_ScriptName%.lnk
FileCreateShortcut, %A_ScriptFullPath%, %A_Startup%\%A_ScriptName%.lnk, %A_ScriptDir%
Return
InstallEitherMouse:
FileCreateDir, %ProgramFiles%\EitherMouse
FileCopy, EitherMouse.ahk, %ProgramFiles%\EitherMouse\EitherMouse.ahk, 1
FileCopy, EitherMouse.ini, %ProgramFiles%\EitherMouse\EitherMouse.ini, 0
FileCopy, EitherMouse.exe, %ProgramFiles%\EitherMouse\EitherMouse.exe, 1
If ErrorLevel = 0
{
FileCreateDir, %A_Programs%\EitherMouse
FileCreateShortcut, %ProgramFiles%\EitherMouse\EitherMouse.exe, %A_Programs%\EitherMouse\EitherMouse.lnk
FileCreateShortcut, %ProgramFiles%\EitherMouse\EitherMouse.ahk, %A_Programs%\EitherMouse\EitherMouse.ahk.lnk
FileCreateShortcut, %ProgramFiles%\EitherMouse\%A_ScriptName%, %A_Startup%\EitherMouse.lnk
Run, %ProgramFiles%\EitherMouse\%A_ScriptName%
ExitApp
}
Return
SaveAssignments:
GoSub, GuiClose
IniWrite, % Swapped, EitherMouse.ini, Assignments, Swapped
IniWrite, % FirstMouse, EitherMouse.ini, Assignments, First Mouse
IniWrite, % SecondMouse, EitherMouse.ini, Assignments, Second Mouse
Return
AboutEitherMouse:
GoSub, GuiClose
Gui, 1:-Caption +Border +AlwaysOnTop +ToolWindow
Gui 1:+LastFound
Gui, 1:Color, White
Gui, 1:Add, Picture, x36 y3 w32 h32 Icon2, % IconFile
Gui, 1:Add, Picture, x68 y3 w32 h32 Icon1, % "main.cpl"
Gui, 1:Add, Picture, x100 y3 w32 h32 Icon1, % IconFile
Gui, 1:Font, s12 w600 cBlack
Gui, 1:Add, Text, x15 y30 w138 h30 Center BackgroundTrans, EitherMouse
Gui, 1:Font, s8 w0
Gui, 1:Add, Text, x5 y48 w158 h15 Center BackgroundTrans, v%Version% - made by joel - aug 09
Gui, 1:Add, Text, x5 y70 w158 h130 Center, Sharing a computer with a left-handed user?`n`nEitherMouse seemlessly swaps mouse buttons for you as the mouse being used changes!`n`nYou can now leave 2 mice connected and use either at any time, immediately
Gui, 1:Add, Button, x154 y2 w12 h12 cSilver gGuiClose, X
Gui, 2:-Caption +Border +AlwaysOnTop +ToolWindow +LabelBackground +E0x20
Gui 2:+LastFound
Gui, 2:Color, Black
WinSet, Transparent, 135
WinSet, Region, 0-0 w276 h296 R27-27
Gui, 2:Show, w276 h296, EitherMouse Background
Gui, 1:Show, w168 h208, EitherMouse %Version%
SetTimer, GuiClose, -15000
Return
ExitEitherMouse:
GoSub, GuiClose
MsgBox, , EitherMouse, Exiting..., .75
ExitApp:
ExitApp
------------
Did you try any of the saving/installing/shortcut options?? Mouse control panel?
Thanks again for trying and replying!
- gwarble