Jump to content
Sign in to follow this  
Aceguy

Func()

Recommended Posts

Aceguy

Do
    sleep(100)
until 1=0

for $c=1 to 9
    hotkeyset($c,"need_to_call_different_func_for_$c")
Next

Func need_to_call_different_func_for_$c()
    MsgBox(0,"","Please help",0)
EndFunc

so for expample if i press 1 mshgbox says i pressed 1 ect...

i would like to try and avoid....

hotkeyset(1,"")

hotkeyset(2,"")

hotkeyset(3,"") ect.

Share this post


Link to post
Share on other sites
FreeFry

Look at the @HotkeyPressed Macro, it returns the key pressed.

Share this post


Link to post
Share on other sites
Aceguy

OK. done it TY.

for $c=1 to 5
    hotkeyset($c,"hot")
Next

Do
    sleep(100)
    
until 1=0

Func hot()
    
    MsgBox(0,"",@HotKeyPressed,0)
    EndFunc

Is this right.

but 1 more thing..... i doesnt register the key on my application/game ARRRRGGGGHHHHH

Share this post


Link to post
Share on other sites
FreeFry

Yes, that's correct, you could use it like this:

Func hot()
    Switch @HotkeyPressed
        Case "1"
            ; do something
        Case "2"
            ; do something
        Case "3"
            ;and so on
    EndSwitch
EndFuncoÝ÷ Øy¦Ê¬k+ajØ­v¬m­è"²×«a{,(®J.¶ÈzØ^©nëg¢Ø§¶ jgv+X¢çÚ"ø§×¥¢l)¶¬{-y§H¶§+,æ­z¶®¶­sevÆR 6ÆVW¥tVæ
Edited by FreeFry

Share this post


Link to post
Share on other sites
FreeFry

Ok, then it might be the game that blocks the hotkeys, or removes them.

Alternatively, you could try setting the hotkeys AFTER the game window is activated and see if they work.

Edit:

Something like this:

Dim $Set = False
Dim $WindowTitle = "Game title here"

While 1
    If WinActive($WindowTitle) And Not $Set Then
        _SetHotKeys(1)
        $Set = True
    ElseIf Not WinActive($WindowTitle) And $Set Then
        _SetHotKeys(0)
        $Set = False
    EndIf
    Sleep(100)
WEnd

Func hot()
    Switch @HotkeyPressed
        Case "1"
            MsgBox(0, "", @HotKeyPressed)
        Case "2"
            MsgBox(0, "", @HotKeyPressed)
        Case "3"
            MsgBox(0, "", @HotKeyPressed)
    EndSwitch
EndFunc

Func _SetHotKeys($State)
    If $State Then
        For $i = 1 To 5
            HotKeySet($i, "hot")
        Next
    Else
        For $i = 1 To 5
            HotKeySet($i)
        Next
    EndIf
EndFunc
Edited by FreeFry

Share this post


Link to post
Share on other sites
Aceguy

thanks. i will try that.

Edit - no joy, damn, there goes my idea.

taken me 3years to get my wife to play this game, all i wanted is a prog to detect when she used a game macro, CTRL+1 for eg. and to notify her when she can use it again.

yes the game has macros but cancel each other out when a new macro is pressed.... was just a aid for her. NVM. thanks to all that replyed.

Edited by Aceguy

Share this post


Link to post
Share on other sites
FreeFry

Hmm, I'm sad to hear that. :/

There might be other ways to be able to sense when a key is pressed though...

The_IsPressed() function perhaps works... But that has to be called quite repeatedly, and quickly to detect key presses..

Edit:

To use that function you'll probably have use of this webpage: http://msdn2.microsoft.com/en-us/library/m...540(VS.85).aspx it shows the key codes for the keys you can check.

Here's how you could use it:

#Include <Misc.au3>

Dim $WindowTitle = "Game title here"

Dim $aKeys[5] = [31, 32, 33, 34, 35] ; 1,2,3,4 & 5

Dim $iDllHandle = DllOpen("user32.dll")

While 1
    If WinActive($WindowTitle) Then
        _CheckKeys()
    EndIf
    Sleep(10)
WEnd

Func _HandleKey($iKey)
    Switch $iKey
        Case 31 ; 11
            ; Key 1 code here..
        Case 32 ; 2
            ; Key 2 code here..
        Case 33 ; 3
            ; and so on...
    EndSwitch
    Sleep(250)
EndFunc   ;==>_HandleKey

Func _CheckKeys()
    For $element In $aKeys
        If _IsPressed($element, $iDllHandle) Then
            _HandleKey($element)
        EndIf
    Next
EndFunc   ;==>_CheckKeys

Sorry for the slow response, been away from the computer. :/

Edited by FreeFry

Share this post


Link to post
Share on other sites
FreeFry

No problem. :D

Did that last method work?

Other than that I only know one more method to detect key strokes...

Share this post


Link to post
Share on other sites
martin

Hurray! :D

if you set a hotkey then when your script detects it the key ii is not available to another process. So if you want to detect it and let the other process see it you need something like this.

Hot()
if @HotKey = "{F1}" then;maybe add 'And winactive($someTitle)'
 HotKeySet("{F1}")
 send("{F1}")
;do something maybe
 HotKeySet("{F1}", "Hot")

endif

endfunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
FreeFry

The one method that works doesn't use HotKey's, it just checks if the key is down or not, and only does so if the game window is active..

Share this post


Link to post
Share on other sites
martin

The one method that works doesn't use HotKey's, it just checks if the key is down or not, and only does so if the game window is active..

Yes, I saw the _IsPressed version, but I just thought I'd add a note about why the HotKey versions weren't working.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
FreeFry

Yes, I saw the _IsPressed version, but I just thought I'd add a note about why the HotKey versions weren't working.

Well the issue is not that his game can't see that the keys are pressed, it's that his own program doesn't detect the keypresses(the hotkey's aren't triggered) when his application has focused.

Edit:

Aceguy, you can just attach the code here inside code tags if you want. :D Unless it has some pictures or something. :P

Edited by FreeFry

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  

×