[AHK niceities] WinKeyLessFix, ScrollwheelEmu, backspacefix

User avatar
off

28 Apr 2012, 22:35

Just wanted to get this in a easily findable spot:
For all scripts, you'll have to install AutoHotKey and create an empty textfile wherein you paste the following, then rename that from .txt to .ahk and run it (and you can add it to 'startup' in your windows startmenu if you feel so inclined).


No WinKeys?
If you have a pre-windows era keyboard that you fancy using, and you are used to win+{key} shortcuts, this is a small script that you can use to replace another key with a windows-key, app/menu-key also included:
Spoiler:

Code: Select all

#SingleInstance force
#UseHook
#InstallKeybdHook
SendMode Input
; numpad will still work normally when numlock is on
; win+hotkeys will work as normal (when numlock is off) (menu+hotkey too)
NumPadDel:: 	send {AppsKey}
NumPadDel Up::	send {AppsKey Up}
NumPadIns:: 	send {RWin Down}
NumPadIns Up::	send {RWin Up}
;since I noticed sometimes RWin got stuck as being held down, I added this as an emergency release:
#+Break:: 		send {RWin Up} ;win+shift+break to 'break' free from an RWin HeldDown situation
No Scrollwheel? (or no horizontal scroll function or no middlemouseclickbutton)
If you have a trackball on your keyboard (an MX-11800 for instance) or even a separate one, and you don't have a middle mouse button nor scrollwheel on that, you can use the following script to replicate the functionality to scroll horizontally and vertically and also to middlemousebuttonclick.
Spoiler:
As posted here, by default it works like this: you press left and right mousebutton at the same time to trigger middle mousebutton if you don't move the ball before you release again; if you do move the ball, scroll mode will be activated, which means that you will scroll in the direction you move the ball.
Instead of pressing LMB+RMB at the same time, you can also use the '5' on your numpad with numlock disabled for the same functionality; ofcourse if you have a single trackball there's no such luck, but you can easily remap that to any extra button you might have available on your trackball.

There is an on/off toggle built-in, see the last line of the script, that as is disables this script when you toggle scroll-lock on, and reenables it when you toggle that off. This is handy because the functionality might interfere with some games. Ofcourse you can remap this to another key, scrolllock is used here so there is a clear (led)indication.

You'll need three scripts, all rehosted right here, all named as stated, and in the same directory.
MouseWheelEmulator is the main one; the one you want to run.

MouseWheelEmulator.ahk by Blahman, page here. Edited by me.

Code: Select all

;; MouseWheelEmulator.ahk

/*
MouseWheelEmulator
Created by Blahman (blah238 at gmail dot com)
v1.0
10/18/2009

Summary: This script combines the functionality of TheGood's AHKHID and ManaUser's MakeChord libraries to provide emulated middle-click and scroll wheel abilities to users of mice, trackpads and trackballs without a scroll wheel.

Features:
-Allows middle clicks and mouse wheel scrolling to be performed on hardware without a physical scroll wheel
-Freezes the mouse cursor in place during virtual mouse wheel scrolling
-Sends scroll wheel messages to window or control under cursor, not just the active window (in supported applications; see note about different scroll modes below)

Installation:
1) Download the AHKHID and MakeChord libraries and place the AHKHID.ahk and MakeChord.ahk files in the same folder as this script.
AHKHID: http://www.autohotkey.com/forum/topic41397.html
MakeChord (just the second half that starts with the MakeChord() function): http://www.autohotkey.com/forum/topic44399.html
2) Run this script.

Usage:
By default there are two ways to activate a middle click or scroll the virtual mouse wheel:
To perform middle-click:
Click the left and right mouse buttons simultaneously (often referred to as "chording").
-or-
Hold Alt and right click.
;Changed to: press numpad5 while numlock is off.

To scroll the virtual mouse wheel:
Click and hold the left and right mouse buttons simultaneously and move the mouse in the direction you wish to scroll.
-or-
Hold Alt, click and hold the right mouse button, and move the mouse in the direction you wish to scroll.
;Changed to: hold numpad5 while numlock is off, drag mouse to scroll.

Note: If you need to terminate the script you can use Ctrl-Alt-Break.

About the different scroll modes:
There are several different ways that any given program may implement mouse scrolling. AHK has built-in WheelUp and WheelDown functions, but not all applications respond to them.
Some applications respond to WM_VSCROLL/WM_HSCROLL messages, while others respond to WM_MOUSEWHEEL/WM_HSCROLL messages.
If you find an application you use doesn't work with this script out of the box, you can probably fix it yourself by adding that application's process name to the conditional statements in the GetScrollMode() function.
The default scroll mode, 0, is AHK's built-in WheelUp and WheelDown commands. This does not support horizontal scrolling or scrolling the window or control under the cursor, while the other two modes do.
Some applications respond to more than one scroll mode, so you can try them all and decide which works best for you.
Finally, to further muddy the waters, some applications have frames within them that respond to scroll messages differently to the rest of the application. An example of this is the AHK help file, which uses the Internet Explorer_Server1 control to display HTML pages in one frame, and standard Windows controls to display the table of contents, index, etc. in another frame, and each responds to different scroll modes. I have tried to account for this in the GetScrollMode() function as well, but there may be other implementations I have not covered. You can use AHK's Window Spy to determine the name of the non-conforming control and write an exception for it, similar to the examples I have provided.
;Now in 1.0+ the default mode 0 does support left and right scrolling.


|[warning] it's advisable to disable during games, might cramp your style.

|v1.0+ mini-edit by off@deskthority, april 2012
|-Added WheelRight/Left to mode 0
|-Added scrolllock as on/off toggle, to disable in games; light on = disabled.
|-Dropped priority and critical, way less unreliable now (for me at least)
|-Changed mouse_threshold to 2 from 3
|-Renamed mouse_moved variable contents from n/y to no/yes to avoid confusion with 'y' variable used
|-Moved firefox from mode 2 to 0, and added notepad++ to mode 1
|All credit where credit is due: 
|Blahman (MouseWheelEmulator v1.0), ManaUser(MakeChord), TheGood (AHKHID),
|LANG (AHK),
|and everyone for sharing scripts and knowledge.
*/
;; Configuration

mouse_Threshold = 2 ;3 ; the number of pixels the mouse must move for a scroll tick to occur
; ^ don't put the ; right next to the active number. will get added to the var otherwise, givingg problems.
MakeChord("LButton", "RButton", "scrollChord", 20) ; Chord to activate middle click or scrolling. See MakeChord.ahk for instructions
scroll_Hotkey = NumpadClear ;is numpad5 w numlock off ;!RButton ; Hotkey to activate middle click or scrolling

;; End Configuration

#SingleInstance Force
#NoEnv
#Persistent
SendMode Input
Process, Priority, , High ;Realtime
#Include %A_ScriptDir%\AHKHID.ahk

;Create GUI to receive messages
Gui, +LastFound
hGui := WinExist()

;Intercept WM_INPUT messages
OnMessage(0x00FF, "InputMsg")

SetDefaultMouseSpeed, 0
scrollMode = 0 ; 0 = MouseClick, WheelUp/WheelDown, 1 = WM_VSCROLL/WM_HSCROLL, 2 = WM_MOUSEWHEEL/WM_HSCROLL
CoordMode, Mouse, Screen


HotKey, %scroll_Hotkey%, scrollChord
HotKey, %scroll_Hotkey% Up, scrollChord_Up
return

scrollChord:
mouse_Moved = no
BlockInput, MouseMove
MouseGetPos, m_x, m_y, winID, control
WinGet, procName, ProcessName, ahk_id %winID%
hw_m_target := DllCall( "WindowFromPoint", "int", m_x, "int", m_y )
GetScrollMode()
HID_Register(1, 2, hGui, RIDEV_INPUTSINK)
return

scrollChord_Up:
ToolTip
BlockInput, MouseMoveOff
HID_Register(1,2,0,RIDEV_REMOVE)
if mouse_Moved = no
    MouseClick, Middle
return

InputMsg(wParam, lParam) {
    local x, y
    ;Critical
    x := HID_GetInputInfo(lParam, II_MSE_LASTX)
    y := HID_GetInputInfo(lParam, II_MSE_LASTY)
    If ((Abs(x) > 0.0) or (Abs(y) > 0.0))
       mouse_Moved = yes
    if y > %mouse_Threshold%
    {
        ScrollDown()
    }
    else if y < -%mouse_Threshold%
	{
        ScrollUp()
    }
	if x > %mouse_Threshold%
    {
        ScrollRight()
    }
    else if x < -%mouse_Threshold%
    {
		ScrollLeft()
    }
   ;ToolTip, % "dX = " . x . "  " . "dY = " . y . a_tab . winID . a_tab . control . a_tab . procName . a_tab . hw_m_target . a_tab . scrollMode
    ;; Uncomment the above line for handy debug info shown while scrolling
}

GetScrollMode()
{
    global
    local ctl_x, ctl_y, ctl_w, ctl_h, ctl_hwnd, win_x, win_y
    if (procName = "notepad++.exe" or procName = "hh.exe" or procName = "iexplore.exe" or procName = "dexplore.exe" or procName = "OUTLOOK.EXE")
    {
        scrollMode = 1
        WinGetPos, win_x, win_y, , , ahk_id %WinID%
        ControlGetPos, ctl_x, ctl_y, ctl_w, ctl_h, Internet Explorer_Server1, ahk_id %WinID%
        if (((m_x >= win_x + ctl_x) and (m_x <= win_x + ctl_x + ctl_w)) and ((m_y >= win_y + ctl_y) and (m_y <= win_y + ctl_y + ctl_h)))
            control = Internet Explorer_Server1
        else
            {
                ControlGetPos, ctl_x, ctl_y, ctl_w, ctl_h, NETUIHWND1, ahk_id %WinID%
                if (((m_x >= win_x + ctl_x) and (m_x <= win_x + ctl_x + ctl_w)) and ((m_y >= win_y + ctl_y) and (m_y <= win_y + ctl_y + ctl_h)))
                    scrollMode = 2
            }
    }
    else if (procName = "notepad.exe" or procName = "explorer.exe" or procName = "EXCEL.exe") ;firefox.exe
        scrollMode = 2
    else ;firefox.exe
        scrollMode = 0
    return
}

ScrollDown()
{
    global
    if (scrollMode = 0)
        MouseClick, WheelDown
    else if (scrollMode = 1)
        PostMessage, 0x115, 1, 0, %control%, ahk_id %winID%
    else
    {
       ; WM_MOUSEWHEEL
       ;   WHEEL_DELTA = 120
       PostMessage, 0x20A, -120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
    }
}

ScrollUp()
{
    global
    if (scrollMode = 0)
        MouseClick, WheelUp
    else if (scrollMode = 1)
       PostMessage, 0x115, 0, 0, %control%, ahk_id %winID%
    else if (scrollMode = 2)
    {
       ; WM_MOUSEWHEEL
       ;   WHEEL_DELTA = 120
       PostMessage, 0x20A, 120 << 16, ( m_y << 16 )|m_x,, ahk_id %hw_m_target%
    }
}

ScrollRight()
{
    global
	if (scrollMode = 0)
        MouseClick, WheelRight
		;Send {WheelRight}
	  else if (scrollMode <> 0)
        ;loop, 2
            SendMessage, 0x114, 1, 0, %control%, ahk_id %winID%
}

ScrollLeft()
{
    global
    if (scrollMode = 0)
        MouseClick, WheelLeft
		;Send {WheelLeft}
	  else if (scrollMode <> 0)
        ;loop, 2
            SendMessage, 0x114, 0, 0, %control%, ahk_id %winID%
}

^!CtrlBreak::ExitApp
~ScrollLock::Suspend, Toggle ;~ is so the light and function will still trigger; you can now tell that this script is disabled when the light is on.

#Include %A_ScriptDir%\MakeChord.ahk
MakeChord.ahk by ManaUser, page here.

Code: Select all

;Chord.ahk by Paul Pliska (ManaUser) - Version 2.0
MakeChord(Note1, Note2, Result, Delay = 0, Context = "")
{
   Local NewChord
   If Context
      HotKey IfWinActive, %Context%
   If Note1 In Ctrl,Alt,Shift
   {
      MakeChord("L" Note1, Note2, Result)
      MakeChord("R" Note1, Note2, Result)
      If Context
         HotKey IfWinActive
      Return
   }
   If Note2 In Ctrl,Alt,Shift
   {
      MakeChord(Note1, "L" Note2, Result)
      MakeChord(Note1, "R" Note2, Result)
      If Context
         HotKey IfWinActive
      Return
   }
   KeyWait % StripMods(Note1)
   KeyWait % StripMods(Note2)
   HotKey *$%Note1%, NoteDown
   HotKey *$%Note2%, NoteDown
   HotKey *$%Note1% Up, NoteUp
   HotKey *$%Note2% Up, NoteUp
   If Context
      HotKey IfWinActive
   NewChord := GetChordName(EscapeNote(Note1), EscapeNote(Note2))
   If NOT InStr(ChordList, NewChord)
   {
      If (ChordList != "")
         ChordList .= "|"
      ChordList .= NewChord
   }
   If NOT RegExMatch(Result, "^[a-zA-Z]\|")
   {
      If IsLabel(Result)
         Result := "L|" Result
      Else If (GetKeyState(Result) != "")
         Result := "K|" Result
      Else
         Result := "S|" Result
   }
   If (ConText = "")
      %NewChord% := Result
   else
   {
      Loop
      {
         Existing := %NewChord%_%A_Index%_Context
         If (Existing = "" OR Existing = Context)
         {
            %NewChord%_%A_Index%_Context := Context
            %NewChord%_%A_Index% := Result
            Break
         }
      }
   }
   If (Delay > 0)
      SetKeyDelay(Delay, Note1 " " Note2)
   If (DefaultKeyDelay = "")
      DefaultKeyDelay := 50
}

SetKeyDelay(Delay, Keys = "")
{
   Global
   If (Keys = "")
      DefaultKeyDelay := Delay
   Loop Parse, Keys, %A_Space%
   {
      Escaped := EscapeNote(A_LoopField)
      %Escaped%_Delay := Delay
   }
}

NoteDown:
   Critical
   ThisKey := GetThisKey()
   if (ThisKey = "$LButton" or ThisKey = "$RButton")
       MouseGetPos, init_x, init_y
   If ChordUsingNote(ThisKey)
      Return
   If (LastNote != "")
   {
      ChordName := GetChordName(LastNote, ThisKey)
      If (NoCreate(ChordName) OR NoCreate(ChordName "_1"))
      {
         Loop
         {
            ThisContext := %ChordName%_%A_Index%_Context
            If (ThisContext = "")
            {
               ThisContextNum = x
               MatchingChord := %ChordName%
               Break
            }
            If WinActive(ThisContext)
            {
               ThisContextNum := A_Index
               MatchingChord := %ChordName%_%A_Index%
               Break
            }
         }
         RegExMatch(MatchingChord, "^([a-zA-Z])\|(.*)$", ChordPart)
         If (ChordPart1 = "L")
            SetTimer %ChordPart2%, -1
         If (ChordPart1 = "S")
            Send %ChordPart2%
         If (ChordPart1 = "K")
            Send % "{blind}{" Ctrl2AltFix(ChordName, ChordPart2) " DownTemp}"
         %ChordName%_Down := ThisContextNum
         SetTimer PressIt, Off
         LastNote =

         Return
      }
      GoSub PressIt
   }
   LastNote := ThisKey
   If (NoCreate(ThisKey "_Delay"))
      SetTimer PressIt, % %ThisKey%_Delay
   else
      SetTimer PressIt, % DefaultKeyDelay
Return

NoteUp:
   Critical
   ThisKey := GetThisKey()
   ChordName := ChordUsingNote(ThisKey)
   If ChordName
   {
      ThisContext := %ChordName%_Down
      If (ThisContext)
      {
         If (ThisContext = "x")
            MatchingChord := %ChordName%
         Else
            MatchingChord := %ChordName%_%ThisContext%

         If (ChordPart1 = "L" AND IsLabel(ChordPart2 "_Up"))
            SetTimer %ChordPart2%_Up, -1
         If (ChordPart1 = "K")
            Send % "{blind}{" ChordPart2 " Up}"
         %ChordName%_Down =
      }
   } 
   If (LastNote != "")
      GoSub PressIt
   If GetKeyState(UnescapeNote(ThisKey, 1))
      Send % "{blind}{" UnescapeNote(ThisKey, 1) " Up}"
Return

PressIt:
   Critical
   if (LastNote = "$LButton" or LastNote = "$RButton")
       MouseMove, init_x, init_y, 0
   Send % "{blind}{" UnescapeNote(LastNote, 1) " Down}"
   SetTimer PressIt, Off
   LastNote =
Return

GetThisKey()
{
   Return EscapeNote(RegExReplace(A_ThisHotkey, "i)[~*$]*(\S+)( Up)?", "$1"))
}

GetChordName(Note1, Note2)
{
   If (Note2 < Note1)
      Return Note2 "_" Note1
   Else
      Return Note1 "_" Note2
}

StripMods(Note)
{
   Return RegExReplace(Note, "^[+^!#]*")
}

EscapeNote(Note)
{
   Scaw = +^!#scaw
   Symbols = !EX@AT#NM$DS`%PC^CT&ND*AS(OP)CP``BT~TL_US+PL-MN=EQ|VB\BK/FW?QM[OS]CS{OC}CC:CN;SC"DQ'SQ,CM.PD<LT>GT
   ModKeys := RegExReplace(Note, "(([#^!+])(?=.)|.+$)", "$2")
   MainKey := SubStr(Note, StrLen(ModKeys) + 1)
   Loop 4
      If InStr(ModKeys, SubStr(Scaw, A_Index, 1))
         Escaped .= SubStr(Scaw, A_Index + 4, 1)
   Match := InStr(Symbols, MainKey, 1)
   If Mod(Match, 3) = 1
      MainKey := SubStr(Symbols, Match + 1, 2)
   Escaped .= "$" MainKey
   Return Escaped
}

UnescapeNote(Note, StripMods = 0)
{
   Scaw = +^!#scaw
   Symbols = !EX@AT#NM$DS`%PC^CT&ND*AS(OP)CP``BT~TL_US+PL-MN=EQ|VB\BK/FW?QM[OS]CS{OC}CC:CN;SC"DQ'SQ,CM.PD<LT>GT
   StringSplit Keys, Note, $
   Match := InStr(Symbols, Keys2, 1)
   If Mod(Match, 3) = 2
      Keys2 := SubStr(Symbols, Match - 1, 1)
   If NOT StripMods
   {
      Loop 4
         If InStr(Keys1, SubStr(Scaw, A_Index + 4, 1))
            Unescaped .= SubStr(Scaw, A_Index, 1)
   }
   Unescaped .= Keys2
   Return Unescaped
}

ChordUsingNote(Note)
{
   Global
   Loop Parse, ChordList, |
   {
      If SubStr("_" A_LoopField "_", "_" Note "_") AND %A_LoopField%_Down
         Return A_LoopField
   }
   Return ""
}

Ctrl2AltFix(Chord, Key)
{
   Local Fix
   Fix =
   If SubStr(Key, "Alt")
   {
      If InStr(Chord, "LCtrl")
         Fix .= "LCtrl Up}{"
      If InStr(Chord, "RCtrl")
         Fix .= "RCtrl Up}{"
   }
   Fix .= Key
   Return Fix
}

NoCreate(TestVar)
{
   Global
   If %TestVar% =
      Return ""
   Else
      Return (%TestVar%)
}
AHKHID.ahk by TheGood, page here.

Code: Select all

/*! TheGood
    AHKHID - An AHK implementation of the HID functions.

You have to put the #Include line in the auto-execute section if you would like to use the constants.

FUNCTION LIST:
________________________________
HID_Initialize(bRefresh = False)

You don't have to call this function manually. It is automatically called by other functions to get the pointer of the
RAWINPUTDEVICELIST struct array. However, if a new device is plugged in, you will have to refresh the listing by calling it
with bRefresh = True. Returns -1 on error (with error message in ErrorLevel).
_________________
HID_GetDevCount()

Returs the number of HID devices connected to this computer.
Returns -1 on error (with error message in ErrorLevel).
___________________
HID_GetDevHandle(i)

Returns the handle of device i (starts at 1).
Mostly used internally for API calls.
_______________________
HID_GetDevIndex(Handle)

Returns the index (starts at 1) of the device in the enumeration with matching handle.
Returns 0 if not found.
___________________________________
HID_GetDevType(i, IsHandle = False)

Returns the type of the device. See the RIM_ constants for possible values.
If IsHandle is false, then i is considered the index (starts at 1) of the device in the enumeration.
Otherwise it is the handle of the device.
___________________________________
HID_GetDevName(i, IsHandle = False)

Returns the name of the device (or empty string on error, with error message in ErrorLevel).
If IsHandle is false, then i is considered the index (starts at 1) of the device in the enumeration.
Otherwise it is the handle of the device.
_________________________________________
HID_GetDevInfo(i, Flag, IsHandle = False)

Retrieves info from the RID_DEVICE_INFO struct. To retrieve a member, simply use the corresponding flag. A list of flags
can be found at the top of the script (the constants starting with DI_). Each flag corresponds to a member in the struct.
If IsHandle is false, then i is considered the index (starts at 1) of the device in the enumeration. Otherwise it is the
handle of the device. Returns -1 on error (with error message in ErrorLevel).

See Example 1 for an example on how to use it. 
____________________________________________________________________________
HID_AddRegister(UsagePage = False, Usage = False, Handle = False, Flags = 0)

Allows you to queue up RAWINPUTDEVICE structures before doing the registration. To use it, you first need to initialize the
variable by calling HID_AddRegister(iNumberOfElements). To then add to the stack, simply call it with the parameters you
want (eg. HID_AddRegister(1,6,MyGuiHandle) for keyboards). When you're finally done, you just have to call HID_Register()
with no parameters. The function returns -1 if the struct is full. Redimensioning the struct will erase all previous structs
added. On success, it returns the address of the array of structs (if you'd rather manipulate it yourself).

See Example 2 for an example on how to use it.

You will need to do this if you want to use advance features of the RAWINPUTDEVICE flags. For example, if you want to
register all devices using Usage Page 1 but would like to exclude devices of Usage Page 1 using Usage 2 (keyboards), then
you need to place two elements in the array. The first one is HID_AddRegister(1,0,MyGuiHandle,RIDEV_PAGEONLY) and the second
one is HID_AddRegister(1,2,MyGuiHandle,RIDEV_EXCLUDE).

Tip: Have a look at all the flags you can use (see the constants starting with RIDEV_). The most useful is RIDEV_INPUTSINK.
Tip: Set Handle to 0 if you want the WM_INPUT messages to go to the window with keyboard focus.
Tip: To unregister, use the flag RIDEV_REMOVE. Note that you also need to use the RIDEV_PAGEONLY flag if the TLC was
registered with it.
_________________________________________________________________________
HID_Register(UsagePage = False, Usage = False, Handle = False, Flags = 0)

This function can be used in two ways. If no parameters are specified, it will use the RAWINPUTDEVICE array created through
HID_AddRegister() and register. Otherwise, it will register only the specified parameters. For example, if you just want to
register the mouse, you can simply do HID_Register(1,2,MyGuiHandle). Returns 0 on success, returns -1 on error (with error
message in ErrorLevel).

See Example 2 for an example on how to use it with the RAWINPUTDEVICE.
See Example 3 for an example on how to use it only with the specified parameters.
_________________________________
HID_GetRegisteredDevs(ByRef uDev)

This function allows you to get an array of the TLCs that have already been registered.
It fills uDev with an array of RAWINPUTDEVICE and returns the number of elements in the array.
Returns -1 on error (with error message in ErrorLevel).

See Example 2 for an example on how to use it.
___________________________________
HID_GetInputInfo(InputHandle, Flag)

This function is used to retrieve the data upon receiving WM_INPUT messages. By passing the lParam of the WM_INPUT (0xFF00)
messages, it can retrieve all the members of the RAWINPUT structure, except the raw data coming from HID devices (use
HID_GetInputData for that). To retrieve a member, simply specify the flag corresponding to the member you want, and call
the function. A list of all the flags can be found at the top of this script (the constants starting with II_). Returns -1
on error (with error message in ErrorLevel).

See Example 2 for an example on how to use it to retrieve each member of the structure.
See Example 3 for an example on how to interpret members which represent flags.

Tip: You have to use Critical in your message function or you might get invalid handle errors.
Tip: You can check the value of wParam to know if the application was in the foreground upon reception (see RIM_INPUT).
__________________________________________
HID_GetInputData(InputHandle, ByRef uData)

This function is used to retrieve the data sent by HID devices of type RIM_TYPEHID (ie. neither keyboard nor mouse) upon
receiving WM_INPUT messages. CAUTION: it does not check if the device is indeed of type HID. It is up to you to do so (you
can use GetInputInfo for that). Specify the lParam of the WM_INPUT (0xFF00) message and the function will put in uData the
raw data received from the device. It will then return the size (number of bytes) of uData. Returns -1 on error (with error
message in ErrorLevel).

See Example 2 for an example on how to use it (although you need an HID device of type RIM_TYPEHID to test it).

*/
;___________________________________
;Flags you can use in HID_GetDevInfo
DI_DEVTYPE                  := 4    ;Type of the device. See RIM_ constants.

DI_MSE_ID                   := 8    ;ID for the mouse device.
DI_MSE_NUMBEROFBUTTONS      := 12   ;Number of buttons for the mouse.
DI_MSE_SAMPLERATE           := 16   ;Number of data points per second. This information may not be applicable for every
                                    ;mouse device.
DI_MSE_HASHORIZONTALWHEEL   := 20   ;Vista only: TRUE if the mouse has a wheel for horizontal scrolling; otherwise, FALSE.

DI_KBD_TYPE                 := 8    ;Type of the keyboard. 
DI_KBD_SUBTYPE              := 12   ;Subtype of the keyboard. 
DI_KBD_KEYBOARDMODE         := 16   ;Scan code mode. 
DI_KBD_NUMBEROFFUNCTIONKEYS := 20   ;Number of function keys on the keyboard.
DI_KBD_NUMBEROFINDICATORS   := 24   ;Number of LED indicators on the keyboard.
DI_KBD_NUMBEROFKEYSTOTAL    := 28   ;Total number of keys on the keyboard. 

DI_HID_VENDORID             := 8    ;Vendor ID for the HID.
DI_HID_PRODUCTID            := 12   ;Product ID for the HID. 
DI_HID_VERSIONNUMBER        := 16   ;Version number for the HID. 
DI_HID_USAGEPAGE            := 20 | 0x0100  ;Top-level collection Usage Page for the device.
DI_HID_USAGE                := 22 | 0x0100  ;Top-level collection Usage for the device.
;_____________________________________
;Flags you can use in HID_GetInputInfo
II_DEVTYPE          := 0    ;Type of the device generating the raw input data. See RIM_ constants.
II_DEVHANDLE        := 8    ;Handle to the device generating the raw input data.

II_MSE_FLAGS        := 16 | 0x0100  ;Mouse state. This member can be any reasonable combination of the following values
                                    ; -> see MOUSE constants.
II_MSE_BUTTONFLAGS  := 20 | 0x0100  ;Transition state of the mouse buttons. This member can be one or more of the following
                                    ;values -> see RI_MOUSE constants.
II_MSE_BUTTONDATA   := 22 | 0x1100  ;If usButtonFlags is RI_MOUSE_WHEEL, this member is a signed value that specifies the
                                    ;wheel delta.
II_MSE_RAWBUTTONS   := 24           ;Raw state of the mouse buttons. 
II_MSE_LASTX        := 28 | 0x1000  ;Motion in the X direction. This is signed relative motion or absolute motion,
                                    ;depending on the value of usFlags.
II_MSE_LASTY        := 32 | 0x1000  ;Motion in the Y direction. This is signed relative motion or absolute motion,
                                    ;depending on the value of usFlags. 
II_MSE_EXTRAINFO    := 36           ;Device-specific additional information for the event. 

II_KBD_MAKECODE     := 16 | 0x0100  ;Scan code from the key depression. The scan code for keyboard overrun is
                                    ;KEYBOARD_OVERRUN_MAKE_CODE.
II_KBD_FLAGS        := 18 | 0x0100  ;Flags for scan code information. It can be one or more of the following values
                                    ;-> see RI_KEY constants.
II_KBD_VKEY         := 22 | 0x0100  ;Microsoft Windows message compatible virtual-key code.
II_KBD_MSG          := 24           ;Corresponding window message, for example WM_KEYDOWN, WM_SYSKEYDOWN, and so forth.
II_KBD_EXTRAINFO    := 28           ;Device-specific additional information for the event.

II_HID_SIZE         := 16           ;Size, in bytes, of each HID input in bRawData.
II_HID_COUNT        := 20           ;Number of HID inputs in bRawData.

;DO NOT USE WITH HID_GetInputInfo. Use HID_GetInputData instead to retrieve the raw data.
II_HID_DATA         := 24           ;Raw input data as an array of bytes.
;__________________________________________________________________________________
;Device type values returned by HID_GetDevType as well as DI_DEVTYPE and II_DEVTYPE
;http://msdn.microsoft.com/en-us/library/ms645568
RIM_TYPEMOUSE       := 0    ;The device is a mouse.
RIM_TYPEKEYBOARD    := 1    ;The device is a keyboard.
RIM_TYPEHID         := 2    ;The device is an Human Interface Device (HID) that is not a keyboard and not a mouse.
;_______________________________________________________________________________________________
;Different flags for RAWINPUTDEVICE structure (to be used with HID_AddRegister and HID_Register)
;http://msdn.microsoft.com/en-us/library/ms645565
RIDEV_REMOVE        := 0x00000001   ;If set, this removes the top level collection from the inclusion list. This tells the
                                    ;operating system to stop reading from a device which matches the top level collection.
RIDEV_EXCLUDE       := 0x00000010   ;If set, this specifies the top level collections to exclude when reading a complete
                                    ;usage page. This flag only affects a TLC whose usage page is already specified with
                                    ;RIDEV_PAGEONLY.
RIDEV_PAGEONLY      := 0x00000020   ;If set, this specifies all devices whose top level collection is from the specified
                                    ;usUsagePage. Note that usUsage must be zero. To exclude a particular top level
                                    ;collection, use RIDEV_EXCLUDE.
RIDEV_NOLEGACY      := 0x00000030   ;If set, this prevents any devices specified by usUsagePage or usUsage from generating
                                    ;legacy messages. This is only for the mouse and keyboard. See Remarks.
RIDEV_INPUTSINK     := 0x00000100   ;If set, this enables the caller to receive the input even when the caller is not in
                                    ;the foreground. Note that hwndTarget must be specified.
RIDEV_CAPTUREMOUSE  := 0x00000200   ;If set, the mouse button click does not activate the other window.
RIDEV_NOHOTKEYS     := 0x00000200   ;If set, the application-defined keyboard device hotkeys are not handled. However, the
                                    ;system hotkeys; for example, ALT+TAB and CTRL+ALT+DEL, are still handled. By default,
                                    ;all keyboard hotkeys are handled. RIDEV_NOHOTKEYS can be specified even if
                                    ;RIDEV_NOLEGACY is not specified and hwndTarget is NULL.
RIDEV_APPKEYS       := 0x00000400   ;Microsoft Windows XP Service Pack 1 (SP1): If set, the application command keys are
                                    ;handled. RIDEV_APPKEYS can be specified only if RIDEV_NOLEGACY is specified for a
                                    ;keyboard device.
RIDEV_EXINPUTSINK   := 0x00001000   ;Vista only: If set, this enables the caller to receive input in the background only if
                                    ;the foreground application does not process it. In other words, if the foreground
                                    ;application is not registered for raw input, then the background application that is
                                    ;registered will receive the input.
;__________________________________________________
;Different values of wParam in the WM_INPUT message
;http://msdn.microsoft.com/en-us/library/ms645590
RIM_INPUT       := 0    ;Input occurred while the application was in the foreground. The application must call
                        ;DefWindowProc so the system can perform cleanup.
RIM_INPUTSINK   := 1    ;Input occurred while the application was not in the foreground. The application must call
                        ;DefWindowProc so the system can perform the cleanup.
;__________________________________
;Flags for GetRawInputData API call
;http://msdn.microsoft.com/en-us/library/ms645596
RID_INPUT    := 0x10000003    ;Get the raw data from the RAWINPUT structure.
RID_HEADER    := 0x10000005    ;Get the header information from the RAWINPUT structure.
;_____________________________________
;Flags for RAWMOUSE (part of RAWINPUT)
;http://msdn.microsoft.com/en-us/library/ms645578

;Flags for the II_MSE_FLAGS member
MOUSE_MOVE_RELATIVE         := 0     ;Mouse movement data is relative to the last mouse position.
MOUSE_MOVE_ABSOLUTE         := 1     ;Mouse movement data is based on absolute position.
MOUSE_VIRTUAL_DESKTOP       := 0x02  ;Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system)
MOUSE_ATTRIBUTES_CHANGED    := 0x04  ;Mouse attributes changed; application needs to query the mouse attributes.

;Flags for the II_MSE_BUTTONFLAGS member
RI_MOUSE_LEFT_BUTTON_DOWN   := 0x0001   ;Self-explanatory
RI_MOUSE_LEFT_BUTTON_UP     := 0x0002   ;Self-explanatory
RI_MOUSE_RIGHT_BUTTON_DOWN  := 0x0004   ;Self-explanatory
RI_MOUSE_RIGHT_BUTTON_UP    := 0x0008   ;Self-explanatory
RI_MOUSE_MIDDLE_BUTTON_DOWN := 0x0010   ;Self-explanatory
RI_MOUSE_MIDDLE_BUTTON_UP   := 0x0020   ;Self-explanatory
RI_MOUSE_BUTTON_4_DOWN      := 0x0040   ;XBUTTON1 changed to down.
RI_MOUSE_BUTTON_4_UP        := 0x0080   ;XBUTTON1 changed to up.
RI_MOUSE_BUTTON_5_DOWN      := 0x0100   ;XBUTTON2 changed to down.
RI_MOUSE_BUTTON_5_UP        := 0x0200   ;XBUTTON2 changed to up.
RI_MOUSE_WHEEL              := 0x0400   ;Raw input comes from a mouse wheel. The wheel delta is stored in usButtonData.
;____________________________________________
;Flags for the RAWKEYBOARD (part of RAWINPUT)
;http://msdn.microsoft.com/en-us/library/ms645575

;Flag for the II_KBD_MAKECODE member in the event of a keyboard overrun
KEYBOARD_OVERRUN_MAKE_CODE  := 0xFF

;Flags for the II_KBD_FLAGS member
RI_KEY_MAKE             := 0
RI_KEY_BREAK            := 1
RI_KEY_E0               := 2
RI_KEY_E1               := 4
RI_KEY_TERMSRV_SET_LED  := 8
RI_KEY_TERMSRV_SHADOW   := 0x10
;____________________________________
;AHKHID FUNCTIONS

HID_Initialize(bRefresh = False) {
    Static uHIDList, bInitialized := False
    
    If bInitialized And Not bRefresh
        Return &uHIDList
    
    ;Get the device count
    r := DllCall("GetRawInputDeviceList", "UInt", 0, "UInt*", iCount, "UInt", 8)
    
    ;Check for error
    If (r = -1) Or ErrorLevel {
        ErrorLevel = GetRawInputDeviceList call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return -1
    }
    
    ;Prep var
    VarSetCapacity(uHIDList, iCount * 8)
    r := DllCall("GetRawInputDeviceList", "UInt", &uHIDList, "UInt*", iCount, "UInt", 8)
    If (r = -1) Or ErrorLevel {
        ErrorLevel = GetRawInputDeviceList call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return -1
    }
    
    bInitialized := True
    Return &uHIDList
}

HID_GetDevCount() {
    
    ;Get the device count
    r := DllCall("GetRawInputDeviceList", "UInt", 0, "UInt*", iCount, "UInt", 8)
    
    ;Check for error
    If (r = -1) Or ErrorLevel {
        ErrorLevel = GetRawInputDeviceList call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return -1
    } Else Return iCount
}

HID_GetDevHandle(i) {
    Return NumGet(HID_Initialize(), (i - 1) * 8)
}

HID_GetDevIndex(Handle) {
    Loop % HID_GetDevCount()
        If (NumGet(HID_Initialize(), (A_Index - 1) * 8) = Handle)
            Return A_Index
    Return 0
}

HID_GetDevType(i, IsHandle = False) {
    Return Not IsHandle ? NumGet(HID_Initialize(), ((i - 1) * 8) + 4)
    : NumGet(HID_Initialize(), ((HID_GetDevIndex(i) - 1) * 8) + 4)
}

HID_GetDevName(i, IsHandle = False) {
    RIDI_DEVICENAME := 0x20000007
    
    ;Get index if i is handle
    h := IsHandle ? i : HID_GetDevHandle(i)
    
    ;Get device name length
    r := DllCall("GetRawInputDeviceInfo", "UInt", h, "UInt", RIDI_DEVICENAME, "UInt", 0, "UInt*", iLength)
    If (r = -1) Or ErrorLevel {
        ErrorLevel = GetRawInputDeviceInfo call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return ""
    }

    ;Get device name
    VarSetCapacity(s, iLength + 1)
    r := DllCall("GetRawInputDeviceInfo", "UInt", h, "UInt", RIDI_DEVICENAME, "Str", s, "UInt*", iLength)
    If (r = -1) Or ErrorLevel {
        ErrorLevel = GetRawInputDeviceInfo call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return ""
    }
    
    Return s
}

HID_GetDevInfo(i, Flag, IsHandle = False) {
    Static uInfo, iLastHandle := 0
    RIDI_DEVICEINFO := 0x2000000b
    
    ;Get index if i is handle
    h := IsHandle ? i : HID_GetDevHandle(i)
    
    ;Check if the handle changed
    If (h = iLastHandle) ;It's the same device. No need to call again
        Return NumGet(uInfo, Flag, HID_NumIsShort(Flag) ? "UShort" : "UInt")
    Else {
        
        ;Get device info buffer size
        r := DllCall("GetRawInputDeviceInfo", "UInt", h, "UInt", RIDI_DEVICEINFO, "UInt", 0, "UInt*", iLength)
        If (r = -1) Or ErrorLevel {
            ErrorLevel = GetRawInputDeviceInfo call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
            Return -1
        }
        
        ;Get device info
        VarSetCapacity(uInfo, iLength)
        NumPut(iLength, uInfo)    ;Put length in struct
        r := DllCall("GetRawInputDeviceInfo", "UInt", h, "UInt", RIDI_DEVICEINFO, "UInt", &uInfo, "UInt*", iLength)
        If (r = -1) Or ErrorLevel {
            ErrorLevel = GetRawInputDeviceInfo call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
            Return -1
        }
        
        ;Successful. Keep handle.
        iLastHandle := h
        
        ;Retrieve data
        Return NumGet(uInfo, Flag, HID_NumIsShort(Flag) ? "UShort" : "UInt")
    }
    
    Return 0
}

HID_AddRegister(UsagePage = False, Usage = False, Handle = False, Flags = 0) {
    Static uDev, iIndex := 0, iCount := 0
    RIDEV_REMOVE  := 0x00000001, RIDEV_EXCLUDE := 0x00000010
    
    ;Check if we just want the address
    If Not (UsagePage Or Usage Or Handle Or Flags)
        Return &uDev
    ;Check if we just want the count
    Else If (UsagePage = "Count")
        Return iCount
    ;Check if we're dimensioning the struct
    Else If UsagePage And Not (Usage Or Handle Or Flags) {
        iCount := UsagePage
        iIndex := 0
        VarSetCapacity(uDev, iCount * 12)
        Return &uDev
    }
    
    ;Check if there's space before adding data to struct
    If (iIndex = iCount)
        Return -1    ;Full capacity
    
    ;Check if hwnd needs to be null
    bNull := (Flags & RIDEV_REMOVE) Or (Flags & RIDEV_EXCLUDE)

    ;Put in struct
    NumPut(UsagePage,           uDev, (iIndex * 12) + 0, "UShort")
    NumPut(Usage,               uDev, (iIndex * 12) + 2, "UShort")
    NumPut(Flags,               uDev, (iIndex * 12) + 4)
    NumPut(bNull ? 0 : Handle,  uDev, (iIndex * 12) + 8)
    
    ;Move to next slot
    iIndex += 1
    
    Return &uDev
}

HID_Register(UsagePage = False, Usage = False, Handle = False, Flags = 0) {
    RIDEV_REMOVE  := 0x00000001, RIDEV_EXCLUDE := 0x00000010
    
    ;Check if we're using the AddRegister array or only a single struct
    If Not (UsagePage Or Usage Or Handle Or Flags) {
        
        ;Call
        r := DllCall("RegisterRawInputDevices", "UInt", HID_AddRegister(), "UInt", HID_AddRegister("Count"), "UInt", 12)
        
        ;Check for error
        If Not r {
            ErrorLevel = RegisterRawInputDevices call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
            Return -1
        }
        
    ;Build struct and call
    } Else {
        
        ;Prep var
        VarSetCapacity(uDev, 12)
        
        ;Check if hwnd needs to be null
        bNull := (Flags & RIDEV_REMOVE) Or (Flags & RIDEV_EXCLUDE)
        
        NumPut(UsagePage,           uDev, 0, "UShort")
        NumPut(Usage,               uDev, 2, "UShort")
        NumPut(Flags,               uDev, 4)
        NumPut(bNull ? 0 : Handle,  uDev, 8)
        
        ;Call
        r := DllCall("RegisterRawInputDevices", "UInt", &uDev, "UInt", 1, "UInt", 12)
        
        ;Check for error
        If Not r {
            ErrorLevel = RegisterRawInputDevices call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
            Return -1
        }
    }
    
    Return 0
}

HID_GetRegisteredDevs(ByRef uDev) {
    
    ;Get length
    VarSetCapacity(iCount, 4, 0)
    r := DllCall("GetRegisteredRawInputDevices", "UInt", 0, "UInt*", iCount, "UInt", 12)
    If ErrorLevel {
        ErrorLevel = GetRegisteredRawInputDevices call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return -1
    }
    
    If (iCount > 0) {
        
        ;Prep var
        VarSetCapacity(uDev, iCount * 12)
        
        ;Call
        r := DllCall("GetRegisteredRawInputDevices", "UInt", &uDev, "UInt*", iCount, "UInt", 12)
        If (r = -1) Or ErrorLevel {
            ErrorLevel = GetRegisteredRawInputDevices call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
            Return -1
        }
    }
    
    Return iCount
}

HID_GetInputInfo(InputHandle, Flag) {
    Static uRawInput, iLastHandle := 0
    RID_INPUT := 0x10000003
    
    ;Check if it's the same handle
    If (InputHandle = iLastHandle) ;We can retrieve the data without having to call again
        Return NumGet(uRawInput, Flag, HID_NumIsShort(Flag) ? (HID_NumIsSigned(Flag) ? "Short" : "UShort") : (HID_NumIsSigned(Flag) ? "Int" : "UInt"))
    Else {    ;We need to get a fresh copy
        
        ;Get raw data size
        r := DllCall("GetRawInputData", "UInt", InputHandle, "UInt", RID_INPUT, "UInt", 0, "UInt*", iSize, "UInt", 16)
        If (r = -1) Or ErrorLevel {
            ErrorLevel = GetRawInputData call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
            Return -1
        }
        
        ;Prep var
        VarSetCapacity(uRawInput, iSize)
        
        ;Get raw data
        r := DllCall("GetRawInputData", "UInt", InputHandle, "UInt", RID_INPUT, "UInt", &uRawInput, "UInt*", iSize, "UInt", 16)
        If (r = -1) Or ErrorLevel {
            ErrorLevel = GetRawInputData call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
            Return -1
        } Else If (r <> iSize) {
            ErrorLevel = GetRawInputData did not return the correct size.`nSize returned: %r%`nSize allocated: %iSize%
            Return -1
        }
        
        ;Keep handle reference of current uRawInput
        iLastHandle := InputHandle
        
        ;Retrieve data
        Return NumGet(uRawInput, Flag, HID_NumIsShort(Flag) ? (HID_NumIsSigned(Flag) ? "Short" : "UShort") : (HID_NumIsSigned(Flag) ? "Int" : "UInt"))
    }
    
    Return 0
}

HID_GetInputData(InputHandle, ByRef uData) {
    RID_INPUT := 0x10000003, ID_HID_SIZE := 16, ID_HID_COUNT := 20, ID_HID_DATA := 24
    
    ;Get raw data size
    r := DllCall("GetRawInputData", "UInt", InputHandle, "UInt", RID_INPUT, "UInt", 0, "UInt*", iSize, "UInt", 16)
    If (r = -1) Or ErrorLevel {
        ErrorLevel = GetRawInputData call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return -1
    }
    
    ;Prep var
    VarSetCapacity(uRawInput, iSize)
    
    ;Get raw data
    r := DllCall("GetRawInputData", "UInt", InputHandle, "UInt", RID_INPUT, "UInt", &uRawInput, "UInt*", iSize, "UInt", 16)
    If (r = -1) Or ErrorLevel {
        ErrorLevel = GetRawInputData call failed.`nReturn value: %r%`nErrorLevel: %ErrorLevel%`nLine: %A_LineNumber%`nLast Error: %A_LastError%
        Return -1
    } Else If (r <> iSize) {
        ErrorLevel = GetRawInputData did not return the correct size.`nSize returned: %r%`nSize allocated: %iSize%
        Return -1
    }
    
    ;Get the size of each HID input and the number of them
    iSize   := NumGet(uRawInput, ID_HID_SIZE)
    iCount  := NumGet(uRawInput, ID_HID_COUNT)
    
    ;Allocate memory
    VarSetCapacity(uData, iSize * iCount)
    
    ;Copy bytes
    DllCall("RtlMoveMemory", UInt, &uData, UInt, &uRawInput + 24, UInt, iSize * iCount)
    
    Return (iSize * iCount)
}

;Internal use only
HID_NumIsShort(ByRef Flag) {
    If (Flag & 0x0100) {
        Flag ^= 0x0100    ;Remove it
        Return True
    } Return False
}

;Internal use only
HID_NumIsSigned(ByRef Flag) {
    If (Flag & 0x1000) {
        Flag ^= 0x1000    ;Remove it
        Return True
    } Return False
}
[code]
No Horizontal scroll on your wheelmouse?
This is a very simple script I've found, made by Lang, the creator of AutoHotkey, that enables horizontal scroll in Firefox and other windows for any scrollwheel; just hold Shift and scroll!
This script is much simpler than MouseWheelEmulator, because it's only meant for mice that already have a wheel, and it is less fleshed out
Spoiler:
I've changed it to use the same technique as the first script here for Firefox (original was stepping with arrow keys).
By default it works with left-shift only, but as it is just a simple plaintext script, feel free to change that.
MWE vs Lang's horiscroll; Lang's supports 2 output methods, MWE supports 5. Not all apps accept the same messages; so if an app doesn't work with either of the two supported in this one, try MWE and copy the method that works from there into here for the app you need.

Code: Select all

;;;; Shift + Scroll as Horizontal Scroll in Firefox. By Lang. Miniedit by off.
~LShift & WheelUp:: ; Scroll left.
	if WinActive("ahk_class MozillaUIWindowClass")
	{
		;Loop 5  ; Scroll Speed
		;send,{left}
		Send {WheelLeft}
	}
	else
	{
		ControlGetFocus, control, A
		Loop 10  ; Scroll Speed
		SendMessage, 0x114, 0, 0, %control%, A ; 0x114 is WM_HSCROLL
	}
	return

~LShift & WheelDown:: ; Scroll right.
	if WinActive("ahk_class MozillaUIWindowClass")
	{
		;Loop 5  ; Scroll Speed
		;send,{right}
		Send {WheelRight}
	}
	else
	{
		ControlGetFocus, control, A
		Loop 10  ; Scroll Speed
		SendMessage, 0x114, 1, 0, %control%, A ; 0x114 is WM_HSCROLL
	}
	return
No more Backspace=DirUP in Win7 explorer?
Well not anymore.
This will fix the 'new and improved' mapping (that Windows 7 introduced in Windows Explorer) that has Backspace go a directory 'back' instead of 'up', bloody annoying imho.
Spoiler:
Back and Forward will still be available through hotkeys or mousebuttons; and hotkeys are actually used in this script to map backspace back to what it should be.

Code: Select all

#SingleInstance force
#NoEnv
SendMode Input
{ ;backspace like pre-win7 explorer, by off
#IfWinActive ahk_class CabinetWClass
backspace::
{ ControlGetFocus , controlWithFocus, ahk_class CabinetWClass
 ;MsgBox, %controlWithFocus%
if (controlWithFocus == "Edit1" || controlWithFocus == "Edit2" || controlWithFocus == "Edit3" || controlWithFocus == "Edit4" || controlWithFocus == "DirectUIHWND1")
   ;directuihwnd1 = search box
   ; directuihwnd3 = explorer main area, systreeview321 = explorer tree area
{ send {BS}
 Return
 }
else
{ send !{UP}
     ; weird warning from autohotkey.com: 
     ; Windows Explorer ignores SendInput's 
     ;  simulation of certain navigational hotkeys 
     ;  such as Alt+LeftArrow. To work around this,
     ;  use either SendEvent !{Left} or SendInput {Backspace}.
 Return
 }
}
}
Map CTRL-Backspace to Delete?
just add this to an .ahk :
^Backspace:: send {Delete} ;Ctrl+Backspace is Delete, but DOES NOT allow for shift+delete)..
^+Backspace:: send {Shift}{Delete} ;So this forces that in.

Dislike F1 but like F2?
Add this to an .ahk :
F1::F2 ;no more help opening, more renaming

Tired of typing something?
Like in my case, the syntax to search for something on geekhack and deskthority through google:
Insert:: send {Space}site:geekhack.org OR site:deskthority.net
Use as term in google after or before the item you want to search for to restrict results to these sites.


Ofcourse all these scripts can be integrated into one*, but my recommendation is to keep the MouseWheeelEmulator separate since that is the only one in my experience to interfere with anything (probably because it locks your cursor for awesome scrolling), so also the only one you'd want to toggle on/off.
*As long as you make sure you don't try to use one key for two functions without taking proper precautions..

small non-script tips:
alt+scroll and shift+scroll step ministeps in firefox,
shift+scroll scrolls horizontally in openoffice calc.
scroll-lock still works in m$office excell supposedly (to scroll).

If anyone else has any nice AHK tricks or scripts to share, this might be a nice place to collect all those.
Last edited by off on 18 May 2012, 15:29, edited 3 times in total.

User avatar
Icarium

29 Apr 2012, 11:06

I'd say make a nice "AHK script snippets" wiki page and take part in the contest! :)

User avatar
off

18 May 2012, 15:24

kick to inform of a change I made so you can force release of 'RWin Down', somehow it gets stuck once in a while over here.

User avatar
Trent

18 May 2012, 16:52

This was much needed, thank you for this! I used KeyTweak to simply change the registry value of Insert to Win but I have been meaning to get into the scripting of AutoHotKey!

Post Reply

Return to “Workshop”