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 

Quick Question! Please look over this short macro!

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





PostPosted: Thu Sep 10, 2009 8:42 pm    Post subject: Quick Question! Please look over this short macro! Reply with quote

Code:

#SingleInstance force
#InstallKeybdHook
#InstallMouseHook


SetTimer, KeepRunning
return

KeepRunning:

  ; Get the process name of the active window (i.e. Notepad.exe)
  WinGet, szProcessName, ProcessName, A
  if szProcessName = BF2142.exe
  {
    Suspend, off
  }
  else
  {
    Suspend, on
  }
return

;
; Disable the Window's keys so they don't switch to desktop while in-game
;
$LWin::   ; Left Windows Button
$RWin::   ; Right Windows Button
   ; Do nothing
return

ThrowC4andExplode()
{
   Send, {5 down}
   Sleep 60
   Send, {5 up}
   Sleep 500
   MouseClick, Left, , , , , D
   Sleep 100
   MouseClick, Left, , , , , U
   Sleep 700
   MouseClick, right, , , , , D
   Sleep 100
   MouseClick, right, , , , , U
   Sleep 200
   MouseClick, left, , , , , D
   Sleep 100
   MouseClick, left, , , , , U
}
return

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SwitchThenDetonate()
{
   MouseClick, Right , , , , , D
   Sleep 100
   MouseClick, Right , , , , , U
   Sleep 300   ;The wait for the switch sequence of detonator.
   MouseClick, Left, , , , , D
   Sleep 100
   MouseClick, Left, , , , , U
}
return

F13::ThrowC4andExplode()
F14::SwitchThenDetonate()


So this is what I've compiled together, using some codes from the BF Macro Summary Thread.

But the sad part is, that IT DOES NOT WORK!

Can someone kindly help me fix this up? Thank you.


P.S. I don't understand what the following does..
Code:
#SingleInstance force
#InstallKeybdHook
#InstallMouseHook


SetTimer, KeepRunning
return
Back to top
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Thu Sep 10, 2009 10:27 pm    Post subject: Reply with quote

You do not have anything that activates the BF game , so you could just be sending blank commands to another window.


The:
Quote:

#SingleInstance force
#InstallKeybdHook
#InstallMouseHook


SetTimer, KeepRunning
return


make it so this script can only have one instance at a time, to avoid mix-ups, and 'installs' the 'drivers' for the KB and Mouse, which pretty much allows KB/Mouse hot keys.

Your SetTimer, is missing a 'delay' after "KeepRunning" so it runs instantly vs after a set duration.


Also:
Code:
$LWin::   ; Left Windows Button
$RWin::   ; Right Windows Button
   ; Do nothing
return
Question

and:
Code:

;why not
F14::   ;instead of "F14::SwitchThenDetonate()"  :?:
{
   MouseClick, Right , , , , , D
   Sleep 100
   MouseClick, Right , , , , , U
   Sleep 300   ;The wait for the switch sequence of detonator.
   MouseClick, Left, , , , , D
   Sleep 100
   MouseClick, Left, , , , , U
}
return





Back to top
View user's profile Send private message
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Thu Sep 10, 2009 10:39 pm    Post subject: Reply with quote

I'd have done it with functions also, leaves you better room to re-use code with different keys. I'm against specifying commands directly to a hotkey if you can write a function of it Smile

yes, I like functions Razz

EDIT: Also, I thing the winkeys are defined to nil just because accidentally hitting a win-key mid-game can be a frustrating experience Razz
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
The Original guy
Guest





PostPosted: Sat Sep 12, 2009 12:46 am    Post subject: Reply with quote

Carcophan wrote:
You do not have anything that activates the BF game , so you could just be sending blank commands to another window.


So what should I add? But the BF game is activated by me..

What should I add in as delay? Just the sleep syntax or does the "delay" syntax exist too? Then how much delay?

yeah, I just like to re-organize them like that.. So I can switch around the keys that are binded to them..

I'm really new and have no idea.. Can someone rewrite it so that it should work?

Thanks,
Jason
Back to top
Original Guy
Guest





PostPosted: Sun Sep 13, 2009 3:36 pm    Post subject: Reply with quote

Anyone know anything about hotkeys here? Please I need a bit of help
Back to top
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Sun Sep 13, 2009 6:02 pm    Post subject: Reply with quote

I don't understand the usage of the timer here. What is it's purpose?

I mean, why not just:

Code:

#SingleInstance force
#InstallKeybdHook
#InstallMouseHook

; define the two functions here

return

#IfWinActive, What ever isBF's window title.
;
; Disable the Window's keys so they don't switch to desktop while in-game
;
$LWin::   ; Left Windows Button
$RWin::   ; Right Windows Button
   ; Do nothing
return

F13::ThrowC4andExplode()

F14::SwitchThenDetonate()

#IfWinActive
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Original Guy
Guest





PostPosted: Mon Sep 14, 2009 12:08 am    Post subject: Reply with quote

AnttiV wrote:
I don't understand the usage of the timer here. What is it's purpose?

I mean, why not just:

Code:

#SingleInstance force
#InstallKeybdHook
#InstallMouseHook

; define the two functions here

return

#IfWinActive, What ever isBF's window title.
;
; Disable the Window's keys so they don't switch to desktop while in-game
;
$LWin::   ; Left Windows Button
$RWin::   ; Right Windows Button
   ; Do nothing
return

F13::ThrowC4andExplode()

F14::SwitchThenDetonate()

#IfWinActive


I still get NO response from the hotkey! I can't figure out why it's doing nothing..
Back to top
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Mon Sep 14, 2009 12:28 am    Post subject: Reply with quote

Experiment with SetKeyDelay and SendMode, games are known to be picky about timings and such.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
OriginGuy
Guest





PostPosted: Tue Sep 15, 2009 12:25 am    Post subject: Reply with quote

I dont understand the SendMode because I haven't used it yet..

But for the SetKeyDelay, I'm using sleep if that works.

I would experiment with the delay times, but the first click, left click, does not even register into the game! It means that hotkey is not working, period..
Back to top
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Tue Sep 15, 2009 12:55 am    Post subject: Reply with quote

No, no. SetKeyDelay is definitely not the same as sleep. With SetKeyDelay, you can define the pause between key presses and the time the key stays pressed. It may be, that the keypress does not register for the simple reason that the game does not have time to notice it.

Thus -> increase the time the key stays pressed and it may work.

http://www.autohotkey.com/docs/commands/SetKeyDelay.htm
http://www.autohotkey.com/docs/commands/SendMode.htm
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
OriginGuy
Guest





PostPosted: Tue Sep 15, 2009 1:31 am    Post subject: Reply with quote

Thanks Smile I'll check out the Tuts and try them out.

I appreciate that you are helping me a lot, thanks!
Back to top
Original Guy
Guest





PostPosted: Sat Sep 19, 2009 12:24 pm    Post subject: Reply with quote

Ok, so i've tried using sendmode and setkeydelay but I think I screwed up on the syntax part... but I don't have enough time to think it over with all the extra curriculars and tutors and lessons and school and sports...
Can someone give me an example of appropriately coded lines into my previous code?
Back to top
AnttiV



Joined: 14 Aug 2009
Posts: 237
Location: Finland

PostPosted: Sat Sep 19, 2009 12:38 pm    Post subject: Reply with quote

Try

Code:
SendMode Input
SetKeyDelay, 50, 50


At the top of the script.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
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