AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need help with toggling keystrokes/mouseclicks on and off.

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Ap0stasy
Guest





PostPosted: Sun Aug 10, 2008 7:07 am    Post subject: Need help with toggling keystrokes/mouseclicks on and off. Reply with quote

Hello,

What I want to do is create a script that holds down Shift and LeftClick when I press f12. I don't want it so I have to hold down f12, only push it once and Shift+Leftclick will be held down until I push f12 again.

Seems really simple, but it isnt o_O?

Any help is appreciated.
Back to top
Guest






PostPosted: Sun Aug 10, 2008 7:12 am    Post subject: Reply with quote

Well I got it to push Shift+Leftclick, but I cannot make it stop ><

this is what i have (F12 starts it, F11 stops it (well it's meant to))

Code:

f12::
Send {Shift Down}
Send {LButton Down}
return

f11::
Send {Shift Up}
Send {LButton Up}
return
Back to top
k3ph



Joined: 20 Jul 2006
Posts: 174

PostPosted: Sun Aug 10, 2008 9:58 am    Post subject: Reply with quote

add the following code caging F12:
Code:
#IfWinActive ahk_class Diablo II
...F12...
#IfWinActive


Code:
#NoEnv
#SingleInstance Force
#Persistent
Critical,On
SetBatchLines,-1
SetKeyDelay,-1
Thread, NoTimers
DetectHiddenWindows, On
CoordMode, Mouse, Screen

Debug := 1 ; set 0 to disable tooltips

F12::
MouseGetPos, X, Y, win
WinGetPos, wX, wY,,, ahk_id %win%
X -= wX, Y -= wY
hwnd := ControlFromPoint(X, Y, "ahk_id " win,"", cX, cY)

switch := !switch
if switch {
   if (Debug = 1) {   
      tooltip F12 activated
      SetTimer, RemoveToolTip, 3000
   }
   PostMessage, 0x100, 0x10 | 0x1, cX & 0xFFFF | (cY & 0xFFFF) << 16,, ahk_id %hwnd%
   PostMessage, 0x201, 0x8 | 0x1, cX & 0xFFFF | (cY & 0xFFFF) << 16,, ahk_id %hwnd%
} else {
   PostMessage, 0x101, 0x10,,, ahk_id %hwnd%
   PostMessage, 0x202, 0x8,,, ahk_id %hwnd%
   if (Debug = 1) {
      tooltip F12 disabled
      SetTimer, RemoveToolTip, 3000
   }
}
return

RemoveToolTip:
   SetTimer, RemoveToolTip, Off
   ToolTip
return

; by Lexikos
ControlFromPoint(X, Y, WinTitle="", WinText="", ByRef cX="", ByRef cY="", ExcludeTitle="", ExcludeText="")
{
    if !(hwnd := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText))
        return false
    VarSetCapacity(pt,8)
    VarSetCapacity(wi,60), NumPut(60,wi)
    DllCall("GetWindowInfo","uint",hwnd,"uint",&wi)
    NumPut(X + (w:=NumGet(wi,4,"int")) - (cw:=NumGet(wi,20,"int")), pt,0)
    NumPut(Y + (h:=NumGet(wi,8,"int")) - (ch:=NumGet(wi,24,"int")), pt,4)
    Loop {
        child := DllCall("ChildWindowFromPointEx","uint",hwnd,"int64",NumGet(pt,0,"int64"),"uint",0x5)
        if !child or child=hwnd
            break
        DllCall("MapWindowPoints","uint",hwnd,"uint",child,"uint",&pt,"uint",1)
        hwnd := child
    }
    cX := NumGet(pt,0,"int")
    cY := NumGet(pt,4,"int")
    return hwnd
}


Note: I really dunno why your game stops receiveing Shift after one sec.
_________________
                                  [ profile | ahk.net | ahk.talk ]


Last edited by k3ph on Sun Aug 10, 2008 11:31 am; edited 4 times in total
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Aug 10, 2008 9:59 am    Post subject: Reply with quote

thanks keph you genius Razz
Back to top
k3ph



Joined: 20 Jul 2006
Posts: 174

PostPosted: Sun Aug 10, 2008 11:40 am    Post subject: Reply with quote

Code:

<00001> 000100C0 P WM_KEYDOWN nVirtKey:VK_CONTROL cRepeat:132 ScanCode:B1 fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000011 lParam:00B10084 time:5:31:09.140 point:(132, 203)]
<00002> 000100C0 P WM_LBUTTONDOWN fwKeys:MK_LBUTTON | MK_CONTROL xPos:132 yPos:177 [wParam:00000009 lParam:00B10084 time:5:31:09.140 point:(132, 203)]
<00003> 000100BA P message:0x04A8 [User-defined:WM_USER+168] wParam:00000000 lParam:00000000 time:5:31:10.109 point:(172, 266)
<00004> 000100BA P message:0x04A8 [User-defined:WM_USER+168] wParam:00000000 lParam:00000000 time:5:31:14.156 point:(171, 354)
<00005> 000100BA P message:0x04A8 [User-defined:WM_USER+168] wParam:00000000 lParam:00000000 time:5:31:21.437 point:(178, 247)
<00006> 000100BA P message:0x04A8 [User-defined:WM_USER+168] wParam:00000000 lParam:00000000 time:5:31:22.265 point:(312, 204)
<00007> 000100C0 P WM_KEYUP nVirtKey:VK_SHIFT cRepeat:0 ScanCode:00 fExtended:0 fAltDown:0 fRepeat:0 fUp:0 [wParam:00000010 lParam:00000000 time:5:31:23.515 point:(313, 204)]
<00008> 000100C0 P WM_LBUTTONUP fwKeys:MK_CONTROL xPos:0 yPos:0 [wParam:00000008 lParam:00000000 time:5:31:23.515 point:(313, 204)]


see ? the shift is hold by a long time, probably something is sending a shift overwriting the sent postmessage
_________________
                                  [ profile | ahk.net | ahk.talk ]
Back to top
View user's profile Send private message
sandman60
Guest





PostPosted: Sun Aug 10, 2008 6:29 pm    Post subject: Make a key toggle Reply with quote

I use a variable to remember the status of the key. An If Else statement toggles key using the variable's value.
Code:

; var1 is blank or N/A if not previously defined, so if statement works even for first key press.

f12::
If var1 =
{
   var1 = T
   Send {Shift Down}
   Send {LButton Down}                     
}
  else 
{
   var1 =
   Send {Shift Up}
   Send {LButton Up}
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group