Sign in to follow this  
Followers 0
sanddoctor

Mouse as a hotkeyset

12 posts in this topic

#1 ·  Posted (edited)

Hello:)

What I want is mouse-right-down = enable shift+w which holds it down <click mouse-right> Mouse-right-up = disable shift+w holding down. This for a game I've difficult setting it up. I've tried to use this script from the forum but I have no luck. This is the script I've been trying to use

HotKeySet(+MouseDown{right}, "hammer_toggle")
global $autohammer = 0
Func hammer_toggle()
   If $autohammer = 0 Then
      Send("+{w down}")
      Sleep(100)
      $autohammer = 1
      HotKeySet("+MouseUp{right}"
      HotKeySet(MouseDown("right"), "hammer_toggle")
   Else
      Send("+{w Up}")
      Sleep(100)
      $autohammer = 0
      HotKeySet("+MouseUp{right}")
      HotKeySet(MouseDown("right"), "hammer_toggle")
   EndIf
EndFunc
; Idle
While 1
   Sleep(10)
Wend

What am I doing wrong?

Edited by sanddoctor

Share this post


Link to post
Share on other sites



Are you certain you can use hotkeyset with a mouse press? Where did you get this from "+MouseDown{right}"

Think you need to investigate _ispressed or a mousehook

Share this post


Link to post
Share on other sites

Are you certain you can use hotkeyset with a mouse press? Where did you get this from "+MouseDown{right}"

Think you need to investigate _ispressed or a mousehook

Weird u cant set the mouse to a hotkeyset. I've never used macros before so if u could help me a bit more with commands ect it would be very helpfull:)

Seen some script that u need shift in your commands and then I tried to improvise with the "+MouseDown{right}" :)

Share this post


Link to post
Share on other sites

Below is the easy way with _ispressed. Notice that you still get a context menu when hitting the right mouse button. If you used a low level mouse hook you could avoid the context menu showing up. But that's for another day :)

Just so you aren't wondering what consolewrite is. When you run a script in scite(press f5) you can have text write to the console (at bottom) for debugging purposes.

Good luck and welcome to the forum.

Picea

#include <Misc.au3>
$dll = DllOpen("user32.dll")
global $autohammer = 0

Func hammer_toggle()

   If $autohammer = 0 Then
    ;  Send("+{w down}")
      Sleep(100)
      $autohammer = 1
      ConsoleWrite("on")
   Else
     ; Send("+{w Up}")
      Sleep(100)
      $autohammer = 0
      ConsoleWrite("off")
    EndIf
EndFunc
; Idle
While 1
    if _IsPressed("02", $dll) and _IsPressed("10", $dll) Then hammer_toggle();right mouse and shift
   Sleep(10)
Wend
1 person likes this

Share this post


Link to post
Share on other sites

really, you weren't even consistent with your attempts =\ but since someone else has posted a solution, here's the help file's content on HotKeySet:

Function Reference HotKeySet

--------------------------------------------------------------------------------

Sets a hotkey that calls a user function.

Parameters

key The key combination to use as the hotkey. Same format as Send().

function [optional] The name of the function to call when the key is pressed. Not specifying this parameter will unset a previous hotkey.

Return Value

Success: Returns 1.

Failure: Returns 0.

Remarks

If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously. (The second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.)

A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted. Exceptions are as follows:

1) If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes. MsgBox and FileSelectFolder are examples of blocking functions. Try the behavior of Shift-Alt-d in the Example.

2) If you have paused the script by clicking on the AutoIt Tray icon, any hotkeys pressed during this paused state are ignored.

The following hotkeys cannot be set:

Ctrl+Alt+Delete It is reserved by Windows

F12 It is also reserved by Windows, according to its API.

NumPad's Enter Key Instead, use {Enter} which captures both Enter keys on the keyboard.

Win+B,D,E,F,L,M,R,U; and Win+Shift+M These are built-in Windows shortcuts. Note: Win+B and Win+L might only be reserved on Windows XP and above.

Alt, Ctrl, Shift, Win These are the modifier keys themselves!

Other Any global hotkeys a user has defined using third-party software, any combos of two or more "base keys" such as '{F1}{F2}', and any keys of the form '{LALT}' or '{ALTDOWN}'.

When you set a hotkey, AutoIt captures the key-press and does not pass it on to the active application, with one exception: the Lock keys (NumLock, CapsLock, and ScrollLock) still toggle their respective state!

To Send() a key combination which will trigger a HotKeySet() event, either use ControlSend() or unregister the HotKeySet() event, otherwise, the Send() event may trigger an infinite loop.

; capture and pass along a keypress
HotKeySet("{Esc}", "captureEsc")
Func captureEsc()
    ; ... can do stuff here
    HotKeySet("{Esc}")
    Send("{Esc}")
    HotKeySet("{Esc}", "captureEsc")
EndFunc

The called function can not be given parameters. They will be ignored.

@HotKeyPressed macro can be used inside the function to handle several keys in the same function.

Related

Send, ControlSend

Example

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage")  ;Shift-Alt-d

;;;; Body of program would go here ;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

the function reference included with your install of autoit is quite handy : "C:\Program Files\AutoIt3\AutoIt.chm"

Share this post


Link to post
Share on other sites

Below is the easy way with _ispressed. Notice that you still get a context menu when hitting the right mouse button. If you used a low level mouse hook you could avoid the context menu showing up. But that's for another day :)

Just so you aren't wondering what consolewrite is. When you run a script in scite(press f5) you can have text write to the console (at bottom) for debugging purposes.

Good luck and welcome to the forum.

Picea

#include <Misc.au3>
$dll = DllOpen("user32.dll")
global $autohammer = 0

Func hammer_toggle()

   If $autohammer = 0 Then
    ;  Send("+{w down}")
      Sleep(100)
      $autohammer = 1
      ConsoleWrite("on")
   Else
     ; Send("+{w Up}")
      Sleep(100)
      $autohammer = 0
      ConsoleWrite("off")
    EndIf
EndFunc
; Idle
While 1
    if _IsPressed("02", $dll) and _IsPressed("10", $dll) Then hammer_toggle();right mouse and shift
   Sleep(10)
Wend

Thx for the help and your replies:) But I cant get the script to work when I run it:( Trust me I've spend several hours on this and I'm not good at it.

Share this post


Link to post
Share on other sites

okay...I think there is another lesson I forgot to give.

When you put ; in front of a line it comments out the line. I did that for the juicy parts and forgot to delete the ;

Change these lines

;  Send("+{w down}")
     ; Send("+{w Up}")

to this

Send("+{w down}")
      Send("+{w Up}")

Share this post


Link to post
Share on other sites

okay...I think there is another lesson I forgot to give.

When you put ; in front of a line it comments out the line. I did that for the juicy parts and forgot to delete the ;

Change these lines

;  Send("+{w down}")
     ; Send("+{w Up}")

to this

Send("+{w down}")
      Send("+{w Up}")

Tried it and still it's not working :) Does it have anything to do with this command or others?

#include <Misc.au3>
$dll = DllOpen("user32.dll")

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Kk it seems to work if I press right mouse and shift as u stated:). But the problem is it's not holding shift+w down when I press right mouse and shift to activate it. It only uses shift if I hold shift down while only "w" is down when the script is enabled. I thought just using right mouse could enable and close the script and not using shift+right mouse to do it.

Edited by sanddoctor

Share this post


Link to post
Share on other sites

Diablo II AutoHammers (with w as standstill?)


-jaenster

Share this post


Link to post
Share on other sites

Look at this: #657180

Maybe, that's what you want.


Best Regards BugFix  

Share this post


Link to post
Share on other sites

Diablo II AutoHammers (with w as standstill?)

No it's for Darkfall where I want to press right mouse to enable shift+w holding down and press mouse right to stop it ;)

Look at this: #657180

Maybe, that's what you want.

Wow thx but I'll try look at it but I'm pretty sure I'll fail trying implement the shift+w in the command :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0