Jump to content

Send command and hotkeyset


Recommended Posts

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
;////////////////////

 

Link to comment
Share on other sites

  • Developers
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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
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

Link to comment
Share on other sites

  • Developers
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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
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?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...