Jump to content
Despotis

Hotykeys and additional parameters

Recommended Posts

Hi community

I'm completely new to the forums and AutoIt at all. I started desktop automation using AHK about four months ago and read about AutoIt two days ago. It seems, AutoIt is much more powerful than AHK, so i think it's worth a test. So i started to "rewrite" my main AHK script, which is used to manage windows (sizes and positions). Since i have multiple variations and don't want to have each and every key set as a hotkey, i'm working with "parameters". So for example make a chrome window ready for watching a youtube video, i press my "main" Hotkey "^#u" followed by "yt{enter}". Now AHK positions my browser in the left top corner and resizes it. If i enter "ytt{enter}", additionally youtube.com is opened. I'm doing this, using the Input function of AHK. Another usage is, that i pass X, Y coordinates as parameters. I'm using this kind of passing parameters a lot.

AutoIt is working with Hotkeys in a completely different way. I checked several Postings and found out, that @HotKeyPressed is my friend. But unfortunately, there is no way to pass additional parameters to the function. _IsPressed seems to be a possibility, but there are 2 caveats for my use. First, i don't want the keys to be send to the current window (because i don't want to have a  keylogger ;-)), second, i don't want to check each and every single key on my keyboard if it's pressed. I could use the InputBox, but i don't like to have this window opened every time i enter a Hotkey. I tried to open the InputBox with negativ X, Y coordinates to hide it, but then the script ignores it and doesn't wait for the input.

So is there a kind of _Pressed function that returns the pressed key, or is there an invisible modal Input i just don't see?

Thanks in advance, any help is appreciated.

Share this post


Link to post
Share on other sites

hi if you want automate  chrome  firefox  and  more   i suggest use  this   UDF 

 

also if is  difficult to use  (for me) i  prefer automate  with _IE for explorer  you can find  in help of autoit

 

Share this post


Link to post
Share on other sites

@faustf

Thanks for your links, but i don't want to move, resize and manipulate not only browser windows. This was just an example. And yes, i'm aware of the WinMove function, which would be the most used function if i get a possibility to have parameters/multiple shortcut combinations.

@Nine

Quote

How do you pass new X and Y coordinates on a key pressed ?  I wonder...

In AHK i have defined a shortcut ^#u which then calls the Input function. This function accepts user input. It's similar to the InputBox in AutoIt, but has no Box/Window. After that input i parse the given string and e.g. "p 50 100" calls WinMove($hWnd, "", 50, 100).

So what i'm looking for is to get a string input after a Hotkey is pressed. The easiest way would be the possibility of hiding the InputBox when waiting for user input.

Share this post


Link to post
Share on other sites
5 minutes ago, faustf said:

short cut   call a function , the  function  read a keybord press

And this is the question. I can't find a function that returns the currently pressed key. I only find _IsPressed, which implicates, that i know what key has to be pressed. 😉
And the most important thing, the pressed key should not be passed to the active application. Iow, i don't want the input entered in notepad.exe if this is the active application.

Share this post


Link to post
Share on other sites

Ok, I think I understand what you want.  After pressing a HotKeySet, you want to simply key in a certain pattern without any box, without even seeing what you are typing.  Is that it ?  If so you could use a hook and a callback to register the keys you typed until a certain key is entered (like {ENTER} for example).

Share this post


Link to post
Share on other sites
On 11/6/2019 at 2:56 PM, Nine said:

Ok, I think I understand what you want.  After pressing a HotKeySet, you want to simply key in a certain pattern without any box, without even seeing what you are typing.  Is that it ?  If so you could use a hook and a callback to register the keys you typed until a certain key is entered (like {ENTER} for example).

Yes, you got me right! 🙂 I'm trying to use shortcuts in a similar way emacs or vim does.
I will check for hooks and callbacks in AutoIt, although i'm close to accept the InputBox. It looks really ugly and since i'm just using hotkeys it makes no sense to have an input box at all.

19 hours ago, AdamUL said:

Have a look at the HotStrings UDF.  

This looks great, but doesn't really work for my problem.

1)

Quote

Modifiers are not supported, for example ^a for {CTRL}a. This is not CaSE SenSiTiVE.

2) The keystrokes are not "intercepted/absorbed". So when i'm typing in a shortcut, the text is written into the active window.

I really wonder, why there is no simple Input in AutoIt like in AHK, although it seems to be much more powerful at all.

Share this post


Link to post
Share on other sites

Maybe something like this ?

#include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>

HotKeySet ("{F1}", "TestPattern")
HotKeySet ("{END}", "_Exit")

While True
  Sleep (100)
WEnd

Func TestPattern ()
  Local $aPattern = GetPattern ("^(\d+) +(\d+)$")
  If Not IsArray ($aPattern) Then Return
  MouseMove ($aPattern[0], $aPattern[1])
EndFunc

Func GetPattern($sRegExp)
  Local $hGUI = GUICreate("", 200, 200, 663, 317, $WS_POPUP, $WS_EX_LAYERED)
  GUISetBkColor(0x0000FF)
  Local $idTxt = GUICtrlCreateInput("", 0, 0, 150, 20, -1)
  _WinAPI_SetLayeredWindowAttributes($hGUI, 0x0000FF)
  GUISetState()
  Local $aTxt
  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $idTxt
        $aTxt = StringRegExp (GUICtrlRead ($idTxt),$sRegExp, $STR_REGEXPARRAYMATCH)
        If Not @error then ExitLoop
    EndSwitch
  WEnd
  GUIDelete ()
  Return $aTxt
EndFunc   ;==>GetPattern

Func _Exit ()
  Exit
EndFunc

Enter 2 numbers separated by a space (e.g. 100 200) then press Enter...You can use getpattern func in all cases where you need to key in some parameters.

Edit : include regexp validation :)

Edited by Nine

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

×
×
  • Create New...