I am on a thinkpad. I have a software called TPMiddle installed to change the behaviour of the midlde button (single press is like a middle mouse click and long press with red trackpoint is the scrolling). However, my goal is to press a button and keep the middle mouse click button pressed. Can you come up with an autohotkey script (v2) turns it on? like maybe mapping the pg up key to activate auto-scroll/middle-button scrolling and then pg down key to deactivate the mode
this doesn't work
#Requires AutoHotkey v2.0
scrolling := false
PgUp:: {
global scrolling
if !scrolling {
scrolling := true
SendEvent("{MButton down}")
}
}
PgDn:: {
global scrolling
if scrolling {
scrolling := false
SendEvent("{MButton up}")
}
}
and this one also not
#Requires AutoHotkey v2.0
scrolling := false
PgUp:: {
global scrolling
if !scrolling {
scrolling := true
HoldMiddleButton(true)
}
}
PgDn:: {
global scrolling
if scrolling {
scrolling := false
HoldMiddleButton(false)
}
}
All i get is that it triggers the regular middle mouse button including the scrolling, but I want to middle button scroll mode with trackpoint
Assistant
Okay, let's try a more robust approach using the lower-level SendInput function via DllCall. This often bypasses higher-level hooks or interpretations that might be interfering (like TPMiddle potentially intercepting standard Send commands).
The issue might be that SendEvent or even the older mouse_eventDllCall are being processed in a way that TPMiddle still interprets as its "single press" or "long press" trigger, rather than a raw "button is now held down" state that the application (like a browser or document viewer) needs for its built-in auto-scroll. SendInput is generally the preferred method for simulating input reliably.
autohotkey
User
doesn't work
Assistant
Okay, this is a tricky situation, and the fact that even SendInput isn't working strongly suggests that TPMiddle is actively intercepting or overriding the standard middle mouse button events before the target application (like your browser) can see the "hold" state needed for its native auto-scroll. TPMiddle is likely designed to prevent the standard middle-click-hold behavior to implement its own scrolling logic.
Let's try a few different approaches and diagnostics:
1. Diagnostic Step: Temporarily Disable TPMiddle
This is the most crucial step to confirm the conflict.
Find the TPMiddle icon in your system tray (usually near the clock).
Right-click on it and choose "Exit" or "Disable" (the exact wording might vary).
After TPMiddle is fully closed, run the last AutoHotkey script I provided (the one using SendInput).
Go to a browser or document.
Press PgUp.
Move the TrackPoint.
Question: Does the native application auto-scroll (the little scroll icon appears) work now when TPMiddle is not running?
If YES: This confirms TPMiddle is the component preventing the AHK script from working as intended. The solution will involve either configuring TPMiddle differently or finding a way for AHK to bypass it (which is proving difficult).
If NO: There might be another issue, perhaps related to the specific application, ThinkPad drivers, or even administrative privileges for AHK.
2. Check TPMiddle Configuration
Since TPMiddle is likely the cause (if the diagnostic above is positive), let's see if it can be configured:
Look for a configuration file for TPMiddle (often TPMiddle.ini in its installation directory or your user profile's AppData folder).
Open it in a text editor.
Look for settings related to:
Middle button pass-through
Ignoring middle clicks under certain conditions
Alternative ways to trigger its scrolling (maybe you can map PgUp to that?)
Disabling the single-click-equals-middle-click feature.
Goal: See if you can configure TPMiddle to ignore the middle button entirely, or to allow the standard hold behavior through, perhaps only when a modifier key is pressed. If you can make TPMiddle ignore the middle button, the AHK script might start working.
User
i actually turned tpmiddle off, and when i run it nothing happens.. so maybe the script should still be improved
Assistant
Okay, that's very useful information! If it doesn't work even with TPMiddle completely turned off, it means TPMiddle wasn't the only thing preventing it, or possibly not the cause at all.
Let's refocus. The goal is to simulate the exact input sequence that triggers the application's native auto-scroll mode.
Crucial Baseline Test:
Make sure TPMiddle is still off.
Make sure the AutoHotkey script is NOT running.
Go to the application where you want auto-scroll (e.g., your web browser).
Physically press and hold the actual middle mouse button (the one between the left and right click buttons below the spacebar, not the TrackPoint itself).
While holding it, move the TrackPoint slightly.
Question: Does the auto-scroll icon appear and scrolling start when you do this manually without any helper software?
If YES: Great! This means the application does support standard middle-click auto-scroll, and we just need to figure out why the simulation isn't working.
If NO: Then the problem isn't the AHK script; either the ThinkPad drivers or the specific application you're testing in doesn't support or allow this standard auto-scroll method. In this case, no amount of AHK scripting trying to simulate a middle-click hold will work. We'd need to find a different approach entirely (if one exists).
Assuming the Baseline Test Works (Manual Middle-Click Hold Activates Auto-Scroll):
Here are the next things to try with the AHK script:
1. Run as Administrator:
Sometimes, applications (especially browsers or system windows) ignore simulated input unless the script sending it has administrator privileges.
Right-click on your .ahk script file.
Select "Run as administrator".
Accept the User Account Control (UAC) prompt if it appears.
Now try pressing PgUp in the target application.
2. Try SendPlay Mode:
SendPlay often works at a lower level than SendInput or SendEvent and can be more effective, especially if driver interactions are involved. It might require the script to be run as administrator.
Use this modified script:
autohotkey
#Requires AutoHotkey v2.0
#SingleInstance Force ; Ensure only one instance runs
Global scrolling := false
; --- Hotkeys ---
PgUp:: {
global scrolling
if !scrolling {
scrolling := true
ToolTip("Middle Button Scroll: ON") ; Optional feedback
SetTimer(RemoveToolTip, -1500) ; Remove tooltip after 1.5 sec
SimulateMiddleButtonHold(true) ; Send MButton Down
}
}
PgDn:: {
global scrolling
if scrolling {
scrolling := false
ToolTip("Middle Button Scroll: OFF") ; Optional feedback
SetTimer(RemoveToolTip, -1500) ; Remove tooltip after 1.5 sec
SimulateMiddleButtonHold(false) ; Send MButton Up
}
}
; --- Function to Simulate Hold using SendInput ---
SimulateMiddleButtonHold(state) {
; Constants for SendInput
INPUT_MOUSE := 0
MOUSEEVENTF_MIDDLEDOWN := 0x0020
MOUSEEVENTF_MIDDLEUP := 0x0040
; Determine the flag based on the desired state (true=down, false=up)
dwFlags := state ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP
; Create INPUT structure(s)
; Allocate memory for one INPUT structure. Size depends on 32-bit vs 64-bit AHK.
; Size = (PtrSize * 2) + (UInt * 6) = 8 + 24 = 32 (32-bit) or 16 + 24 = 40 (64-bit)
input := Buffer(A_PtrSize = 8 ? 40 : 32, 0) ; Initialize buffer with zeros
; Populate the INPUT structure for a mouse event
NumPut("UInt", INPUT_MOUSE, input, 0) ; Input type = Mouse
; Offset for MOUSEINPUT structure within INPUT structure is A_PtrSize
NumPut("UInt", dwFlags, input, A_PtrSize + 8) ; dwFlags (offset: PtrSize + Long + Long = PtrSize + 8)
; Call SendInput API function
; Parameters: nInputs (UInt), pInputs (Ptr), cbSize (Int)
DllCall("SendInput", "UInt", 1, "Ptr", input.Ptr, "Int", input.Size)
}
; --- Helper Function for Tooltip ---
RemoveToolTip() {
ToolTip() ; Clears the tooltip
}
; --- Optional: Ensure MButton is released if script exits unexpectedly ---
OnExit(ExitReason, ExitCode) {
if (scrolling) { ; Check if the button was left held down
SimulateMiddleButtonHold(false) ; Release it
OutputDebug("Middle button released on exit due to: " ExitReason)
}
ExitApp(ExitCode) ; Continue with normal exit
}
Explanation:
#Requires AutoHotkey v2.0: Specifies v2 syntax.
#SingleInstance Force: Prevents multiple copies of the script from running.
Global scrolling := false: Initializes the state variable.
PgUp Hotkey:
Checks if scrolling is false.
Sets scrolling to true.
Shows a temporary ToolTip for visual feedback (optional).
Calls SimulateMiddleButtonHold(true) to send the MButton Down event using SendInput.
PgDn Hotkey:
Checks if scrolling is true.
Sets scrolling to false.
Shows a temporary ToolTip (optional).
Calls SimulateMiddleButtonHold(false) to send the MButton Up event using SendInput.
SimulateMiddleButtonHold(state) Function:
Defines constants needed for the SendInputDllCall.
Sets the appropriate mouse event flag (MOUSEEVENTF_MIDDLEDOWN or MOUSEEVENTF_MIDDLEUP).
Allocates a Buffer large enough to hold one INPUT structure. The size depends on whether you are running a 32-bit or 64-bit version of AutoHotkey.
Uses NumPut to correctly place the values (INPUT_MOUSE type and the dwFlags) into the buffer at the right offsets within the structure.
Calls the SendInput function from user32.dll with the prepared buffer. This sends a very low-level input event.
RemoveToolTip() Function: Simple helper to clear the tooltip after a delay.
OnExit Function: This is a safety measure. If the script exits for any reason while the middle button is virtually held down, it attempts to send the "up" signal to avoid getting stuck.
Why this might work better:
Lower Level:SendInput operates at a lower level than SendEvent or the older mouse_event. It's less likely to be intercepted or misinterpreted by intermediate software hooks (like TPMiddle might be using).
Direct Simulation: It directly injects the mouse event into the system input stream, mimicking hardware input more closely.
Before Running:
Save the code as a .ahk file (e.g., MiddleScrollToggle.ahk).
Ensure you have AutoHotkey v2 installed.
Close any previous versions of this script if they are running.
Run the script.
Testing:
Open a window where middle-click scrolling normally works (like a web browser or long document).
Press PgUp. You should see the "ON" tooltip briefly.
Without clicking anything else, move your TrackPoint. Does the auto-scroll cursor appear and scrolling initiate?
Press PgDn. You should see the "OFF" tooltip, and the auto-scroll should stop (the MButton Up event is sent).
If this still doesn't work, it strongly suggests that TPMiddle's hooks are very effective and might be intercepting even SendInput, or that the specific application requires more than just the button state (e.g., a slight physical mouse/trackpoint movement immediately after the click). In that case, you might need to explore TPMiddle's own configuration options to see if you can achieve your goal through it, or temporarily disable TPMiddle to confirm it's the source of the conflict.
3. AHK Alternative: Simulate Click + Tiny Move
Sometimes, auto-scroll requires not just the button down, but an immediate tiny mouse movement after the button goes down. Let's modify the SendInput script to add this.
autohotkey
#Requires AutoHotkey v2.0
#SingleInstance Force
Global scrolling := false
PgUp:: {
global scrolling
if !scrolling {
scrolling := true
ToolTip("Middle Button Scroll: ON")
SetTimer(RemoveToolTip, -1500)
; Send MButton Down
SimulateMiddleButtonEvent(true)
; Wait a tiny bit for the system to register the down state
Sleep(20)
; Simulate a tiny mouse move (1 pixel right) - sometimes needed to trigger auto-scroll mode
SimulateMouseMove(1, 0)
}
}
PgDn:: {
global scrolling
if scrolling {
scrolling := false
ToolTip("Middle Button Scroll: OFF")
SetTimer(RemoveToolTip, -1500)
; Send MButton Up
SimulateMiddleButtonEvent(false)
}
}
SimulateMiddleButtonEvent(state) {
INPUT_MOUSE := 0
MOUSEEVENTF_MIDDLEDOWN := 0x0020
MOUSEEVENTF_MIDDLEUP := 0x0040
dwFlags := state ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP
input := Buffer(A_PtrSize = 8 ? 40 : 32, 0)
NumPut("UInt", INPUT_MOUSE, input, 0)
NumPut("UInt", dwFlags, input, A_PtrSize + 8)
DllCall("SendInput", "UInt", 1, "Ptr", input.Ptr, "Int", input.Size)
}
SimulateMouseMove(dx, dy) {
INPUT_MOUSE := 0
MOUSEEVENTF_MOVE := 0x0001
input := Buffer(A_PtrSize = 8 ? 40 : 32, 0)
NumPut("UInt", INPUT_MOUSE, input, 0) ; Type = Mouse
NumPut("Int", dx, input, A_PtrSize) ; dx
NumPut("Int", dy, input, A_PtrSize + 4) ; dy
NumPut("UInt", MOUSEEVENTF_MOVE, input, A_PtrSize + 8) ; dwFlags
DllCall("SendInput", "UInt", 1, "Ptr", input.Ptr, "Int", input.Size)
}
RemoveToolTip() {
ToolTip()
}
OnExit(ExitReason, ExitCode) {
if (scrolling) {
SimulateMiddleButtonEvent(false)
OutputDebug("Middle button released on exit due to: " ExitReason)
}
ExitApp(ExitCode)
}
Changes:
Added Sleep(20) after sending MButton Down just in case timing is critical.
Added a call to SimulateMouseMove(1, 0) right after the sleep. This sends a tiny 1-pixel move event to the right.
Renamed the main function to SimulateMiddleButtonEvent for clarity.
Added the SimulateMouseMove function using SendInput.
Testing this new script:
Try it with TPMiddle running.
If it fails, try it without TPMiddle running (as per diagnostic step 1).
4. Alternative Activation Method (Application Dependent)
Does the application you want to scroll in have another way to activate auto-scroll?
Sometimes Shift + Middle Click works.
Sometimes there's a dedicated keyboard shortcut in the application itself.
If you find one, you could map PgUp to that combination instead:
autohotkey
; Example if Shift+MiddleClick works
PgUp::Send("+{MButton}")
PgDn::ToolTip("Press PgUp to start auto-scroll") ; PgDn doesn't need to do anything here
This avoids the problematic "hold" simulation entirely.
Summary of Steps to Try:
Disable TPMiddle and test the SendInput script (the one from my previous answer without the mouse move). Does it work now?
If yes, investigate TPMiddle's configuration (TPMiddle.ini) for pass-through or disabling options.
If disabling TPMiddle worked but you can't configure it favorably, try the new AHK script (Attempt #3 above) which adds a tiny mouse move after the MButton down. Test with and without TPMiddle running.
Investigate if the target application has an alternative activation shortcut for auto-scroll (like Shift+MButton) and map PgUp to that instead.
Please report back on the results of step 1 (disabling TPMiddle) first, as that will guide the next best action.
#Requires AutoHotkey v2.0
#SingleInstance Force
; Try SendPlay mode - often requires Admin rights
SendMode("Play")
Global scrolling := false
PgUp:: {
global scrolling
OutputDebug("PgUp pressed. Current scrolling state: " . scrolling) ; Debug
if !scrolling {
scrolling := true
ToolTip("Middle Button Scroll (Play): ON")
SetTimer(RemoveToolTip, -1500)
Send("{MButton Down}") ; Send MButton Down using SendPlay
OutputDebug("Sent {MButton Down} via SendPlay") ; Debug
; Note: Adding a tiny move might still be needed with SendPlay sometimes
; Sleep(30) ; Short delay
; Send("{MouseMove 1, 0, 0, R}") ; Tiny relative move (optional, test without first)
} Else {
OutputDebug("PgUp ignored, already scrolling.")
}
}
PgDn:: {
global scrolling
OutputDebug("PgDn pressed. Current scrolling state: " . scrolling) ; Debug
if scrolling {
scrolling := false
ToolTip("Middle Button Scroll (Play): OFF")
SetTimer(RemoveToolTip, -1500)
Send("{MButton Up}") ; Send MButton Up using SendPlay
OutputDebug("Sent {MButton Up} via SendPlay") ; Debug
} Else {
OutputDebug("PgDn ignored, not currently scrolling.")
}
}
RemoveToolTip() {
ToolTip()
}
; --- Optional: Ensure MButton is released if script exits unexpectedly ---
OnExit(ExitReason, ExitCode) {
if (scrolling) {
Send("{MButton Up}") ; Use SendPlay to release
OutputDebug("Middle button (Play) released on exit due to: " ExitReason)
}
ExitApp(ExitCode)
}
; --- Function to view Debug Output ---
; Press F1 to see the debug messages (requires an editor like SciTE4AutoHotkey or VS Code with AHK extension, or use DebugView from Sysinternals)
F1::ListLines() ; Or use OutputDebugView http://www.autohotkey.com/docs/v1/lib/OutputDebug.htm
How to Use SendPlay Script:
Save this code as a new .ahk file.
Run it as Administrator.
Test PgUp and PgDn.
Use F1 (or a DebugView tool) to see the OutputDebug messages, which can help confirm if the hotkeys are even firing.
3. Check ThinkPad Driver Settings:
Go to Windows Settings -> Bluetooth & devices -> Mouse -> Additional mouse settings.
Look for a tab related to "ThinkPad", "UltraNav", or "TrackPoint".
Explore the settings there. Is there anything related to middle-click behavior, scrolling modes, or button assignments that might be overriding standard Windows behavior even when TPMiddle is off? Sometimes there's an option to choose between "Standard Middle Click" and "Scrolling" for the middle button. Ensure it's set to standard if available.
Let's summarize the immediate steps:
Perform the Baseline Test (manual physical middle-click hold) and report the result.
If the baseline test works, try running the previous SendInput script (the one from my second answer with the tiny move) as Administrator.
If that fails, try the new SendPlay script above, again running as Administrator.
Tell me the results of these steps, especially the baseline test.