Hotkeys for Google/Trimble Sketchup Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Morberis
Posts: 3
Joined: 20 Jan 2021, 14:08

Hotkeys for Google/Trimble Sketchup

20 Jan 2021, 14:22

I apologize, I've been trying for a while now to get this to work. I've done some googling, done some searching of the help page but I haven't got this specific thing to work.

I'm trying to have Autohotkey hold down Shift and Middle mouse button while I hold down the middle mouse button and release the shift and middle mouse button when I release the middle mouse button but only when I have sketchup open.

Here is my quick script as it is now

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Sketchup
#IfWinActive ahk_exe SketchUp.exe
MButton::
send {+ down}{Mbutton down}
return
MButton Up::
Send {+ up}{Mbutton up}
return
I have also tried

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Sketchup
#IfWinActive ahk_exe SketchUp.exe
~MButton::
send {+ down}
return
~MButton Up::
Send {+ up}
return
also

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Sketchup
#IfWinActive ahk_exe SketchUp.exe
MButton::
send {+ down Mbutton down}
return
MButton Up::
Send {+ up Mbutton up}
return
and

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Sketchup
#IfWinActive ahk_exe SketchUp.exe
MButton::
send {+Mbutton down}
return
MButton Up::
Send {+Mbutton up}
return
I've also tried it with #InstallMouseHook and with Sendinput instead of Send. I've tried a few other things that I can't recall. I can definitely have my middle mouse button do hotkey events in Sketchup but it's the holding down of both keys while I hold down the key that seems to be the problem.

If anyone could tell me what I'm doing wrong I'd be super grateful.
Last edited by BoBo on 20 Jan 2021, 18:11, edited 1 time in total.
Reason: Changed subject line from 'Script for Sketchup' to 'Hotkeys for Google/Trimble Sketchub' - to be more specific. HTH ;o)
BoBo
Posts: 4362
Joined: 13 May 2014, 17:15

Re: Hotkeys for Google/Trimble Sketchup

20 Jan 2021, 18:14

Just out of curiosity (and bc Sketchup came to my mind yesterday), do you have any web content where you showcase your Sketchup output?? Greets :thumbup:
BTW; I'd guess my fellow Germans @Rohwedder and/or @gregster would be able to give you some advice. Good luck. :)
Morberis
Posts: 3
Joined: 20 Jan 2021, 14:08

Re: Hotkeys for Google/Trimble Sketchup

20 Jan 2021, 18:57

I don't. It's mostly building designs for various dairies so that we can plan out different things like cow flow, flow type, etc etc. We do have the various robots and equipment modeled but I can't share those unfortunately.

I decided to test things out in notepad with different keys than shift (+) and MButton so that I could see the output.

I thought that at first my problem was that I wasn't emulating a keyboard well enough to work in Sketchup. Where if I hold down a key like "a" on a keyboard it would send the command every 100ms or so. But I'm running into problems trying to get holding MButton to result in repeated a's

I found that I can't seem to use keystate or keywait correctly with the MButton but MButton Up does work. I'm not sure if this is because of things to do with a mouse button press or because of my mouse, a logitech MX Ergo. One attempt is below but all I ever get is a single "b"

Code: Select all

$MButton::
    KeyWait MButton, T0.5                 ; Wait 1/2 second for user to release "a" key
    If ErrorLevel                   ; Still held down
        While GetKeyState("MButton","p"){ ; While it is held down

            Send a
            Sleep 50
        }
    Else                            ; They let go in time
        Send b
return
In fact trying many of my previously code substituting a for MButton results only in a single capital A. If sketchup is looking to see a series of repeated Shift presses and something with MButton I could see why it wouldn't work. In many of these if I change the hotkey from Mbutton to something like "d" things work (I get repeated AAAAAAAA) so that's fun.


Eventually I will probably be using AHK for a few things so I'd prefer to write this so that other AHK's work while I'm using this AHK. I should probably figure out a better way of debugging my scripts.
BoBo
Posts: 4362
Joined: 13 May 2014, 17:15

Re: Hotkeys for Google/Trimble Sketchup

20 Jan 2021, 19:07

While waiting for some valuable support you could have a try to sort out if your device is working with some special keys/output that needs whatever workaround:
https://www.autohotkey.com/docs/KeyList.htm#SpecialKeys
User avatar
boiler
Posts: 6873
Joined: 21 Dec 2014, 02:44

Re: Hotkeys for Google/Trimble Sketchup  Topic is solved

20 Jan 2021, 22:01

The + symbol is only used for the Shift key when used as a modifier such as +{MButton down} (note that it appears before the opening brace of the key it is modifying if the key requires braces, not inside the braces). In this case, you don’t want to use it as a modifier since you want to have it held down as well, not released. You would use the key name {Shift} along with the down option. Thus, it would be:

Code: Select all

#IfWinActive, ahk_exe SketchUp.exe
MButton::Send, {Shift down}{MButton down}
MButton Up::Send, {MButton up}{Shift up}
Note that single-line hotkey definitions don’t need a return after them as they include an implied return when the command is on the same line as the hotkey.
Morberis
Posts: 3
Joined: 20 Jan 2021, 14:08

Re: Hotkeys for Google/Trimble Sketchup

21 Jan 2021, 10:10

boiler wrote:
20 Jan 2021, 22:01
The + symbol is only used for the Shift key when used as a modifier such as +{MButton down} (note that it appears before the opening brace of the key it is modifying if the key requires braces, not inside the braces). In this case, you don’t want to use it as a modifier since you want to have it held down as well, not released. You would use the key name {Shift} along with the down option. Thus, it would be:

Code: Select all

#IfWinActive, ahk_exe SketchUp.exe
MButton::Send, {Shift down}{MButton down}
MButton Up::Send, {MButton up}{Shift up}
Note that single-line hotkey definitions don’t need a return after them as they include an implied return when the command is on the same line as the hotkey.
Thank you, I had not seen that at all. Totally works now. You have my gratitude.

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, braunbaer, Google [Bot], malcev, mikeyww, neo256, newbieforever, swub and 53 guests