swipeales

Send command and hotkeyset

16 posts in this topic

Hello,i am new here and  decided to give a shot to autoit (i use(d) ahk). 

I have problem with send command, i want to send key f which would send f and key d would send {d 2}, a sends l

That doesn't work for f and d, only works for a. 

; Script Start - Add your code below here

;\\\\\\\\\\\\\\\\\\\\Set hotkeys
HotKeySet("f", "_fTest")
HotKeySet("d", "_dTest")
HotKEySet("a", "_aTest")
HotKeySet("F1", "_Exit")
;////////////////////

;\\\\\\\\\\\\\\\\\\\\Declare vars

;////////////////////

;\\\\\\\\\\\\\\\\\\\\Main loop

While 1
    Sleep(1000)
WEnd
;////////////////////

;\\\\\\\\\\\\\\\\\\\\Functions
Func _fTest()
    Send("{f}")
EndFunc   ;==>_Start

Func _dTest()
   Send("{d 2}")
EndFunc   ;==>_Pause

Func _aTest()
   Send("{l}")
EndFunc

Func _Exit()
    Exit
EndFunc   ;==>_Exit
;////////////////////

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

use it this way:

Func _fTest()
    HotKeySet("f")
    Send("f")
    HotKeySet("f", "_fTest")
EndFunc

 

Edited by AutoBert
1 person likes this

Share this post


Link to post
Share on other sites
32 minutes ago, AutoBert said:

use it this way:

Func _fTest()
    HotKeySet("f")
    Send("{f}")
    HotKeySet("f", "_fTest")
EndFunc

thanks, i'd really like to use it the way i posted. I like things to be in order, is there any other solution?

 

Share this post


Link to post
Share on other sites
16 minutes ago, swipeales said:

i'd really like to use it the way i posted. I like things to be in order, is there any other solution?

No idea what you mean as the solution provide will do that, or else tell us what you are looking for?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
18 minutes ago, Jos said:

No idea what you mean as the solution provide will do that, or else tell us what you are looking for?

Jos

i'd like to have for every hotkey a function. A calls aTest B calls bTest. Inside functions i would have keys to be pressed. 

Also, i have found one more issue, if i do something like this:

 

;sorry for the syntax just demonstration purpose (pseudocode)

hotkeyset(e,e_Function) 
hotkeyset(d,d_Function) 

call the function 

Func e_Function()
  Send d
endFunc

Func d_Function()
  Send d 2
endFunc

 

This will always call function d_Function (it will always say dd even if i call e, it will overwrite with dd). Thanks in advance for any help

Share this post


Link to post
Share on other sites

Understood, but you have to disable the HotKey before sending the character or else you activate the hotkey again. That is why AutoBert posted the one example Func for the letter f.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
1 hour ago, AutoBert said:

use it this way:

Func _fTest()
    HotKeySet("f")
    Send("f")
    HotKeySet("f", "_fTest")
EndFunc

 

 

21 minutes ago, Jos said:

Understood, but you have to disable the HotKey before sending the character or else you activate the hotkey again. That is why AutoBert posted the one example Func for the letter f.

Jos

 

I just tried  function fTest  from AutoBer,  and it prints f not d. Here is code:

HotKeySet("f", "_fTest")

Func _fTest()
    HotKeySet("f")
    Send("d")
    HotKeySet("f", "_fTest")
EndFunc

I have also one more question, if script won't terminate even though i closed it, it would go nuts and i can't use my keyboard, I had to restart my computer several times due this.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Reading helpfile for a func which don't works like expected is always a good idea, after them testing the example(s) mostly gives good ideas.

 

Edited by AutoBert

Share this post


Link to post
Share on other sites
Just now, AutoBert said:

Reading helpfile for a func which works like expected is always a good idea, after them testing the example(s) mostly gives good ideas.

 

just tested it first time i hit f key it does nothing (but it should click d), looks like after that script pauses and keeps using normal f. I used your code

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

1 hour ago, swipeales said:

but it should click d

It doesn't click anything but send a "d" to the active window.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
3 hours ago, Jos said:

It doesn't click anything but send a "d" to the active window.

Jos

 

yeh haha my bad i mean it doesn't send d. it sends nothing then pauses a script

Share this post


Link to post
Share on other sites
HotKeySet("f", "_fTest")
HotKeySet("d", "_dTest")
HotKEySet("a", "_aTest")

AutoItSetOption("WinTitleMatchMode", -2)

Global $hWnd = WinGetHandle("VLC media player")

While 1
    Sleep(1000)
WEnd

Func _fTest()
    ControlSend($hWnd, "", "", "f")
EndFunc   ;==>_Start

Func _dTest()
    ControlSend($hWnd, "", "", "d")
EndFunc   ;==>_Pause

Func _aTest()
    ControlSend($hWnd, "", "", "a")
EndFunc

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Using controlsend you can keep the hotkeys set without having to un-register then re-register. I used VLC as an example, because I have it open. Just substitute whatever program you're trying to use send on.

Share this post


Link to post
Share on other sites
13 hours ago, Jos said:
6 hours ago, Jos said:

It will send it for sure ...  what program are you trying to send it to?

Jos

i was testing it on google chrome url, it wouldn't work

5 hours ago, InunoTaishou said:
HotKeySet("f", "_fTest")
HotKeySet("d", "_dTest")
HotKEySet("a", "_aTest")

AutoItSetOption("WinTitleMatchMode", -2)

Global $hWnd = WinGetHandle("VLC media player")

While 1
    Sleep(1000)
WEnd

Func _fTest()
    ControlSend($hWnd, "", "", "f")
EndFunc   ;==>_Start

Func _dTest()
    ControlSend($hWnd, "", "", "d")
EndFunc   ;==>_Pause

Func _aTest()
    ControlSend($hWnd, "", "", "a")
EndFunc

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Using controlsend you can keep the hotkeys set without having to un-register then re-register. I used VLC as an example, because I have it open. Just substitute whatever program you're trying to use send on.

I will try this, but i've heard ControlSend method is slower than Send method, is this true?

Share this post


Link to post
Share on other sites

I don't know how it would be, and even if it was, you'd be talking micros of a milisecond difference between the two.  You could always run a test to see which is faster, disabling the hot key, send, enable the hot key, or controlsend.

1 person likes this

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