Easy scripting question for the pros and cons

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jamesarthur26
Posts: 1
Joined: 16 Jun 2018, 04:39

Easy scripting question for the pros and cons

29 Sep 2018, 21:50

Hi all,

Is it possible to make a program only be able to run while a particular text box inside a particular window is focused/cursor placement? If so, could some one point me to the documentation or tut on that info.

Thanks,
Jason
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Easy scripting question for the pros and cons

30 Sep 2018, 06:15

I suggest you try doing an #if context sensitive following this example2 from the docs:

Code: Select all

; Example 2: Simple word-delete shortcuts for all Edit controls.
#If ActiveControlIsOfClass("Edit")  ;this is a function call looking for "Edit"
^BS::Send ^+{Left}{Del}
^Del::Send ^+{Right}{Del}

ActiveControlIsOfClass(Class) {  ;this is the function being called and the following check ups happen
    ControlGetFocus, FocusedControl, A
    ControlGet, FocusedControlHwnd, Hwnd,, %FocusedControl%, A
    WinGetClass, FocusedControlClass, ahk_id %FocusedControlHwnd%
    return (FocusedControlClass=Class)
}
https://autohotkey.com/docs/commands/_If.htm


I have one script using this example which allows me.to create a really custom.behabior for any focused control.
You can even have dynamic control names like edit_1 edit_2 etc in a GUI. You can check the dynamic names with RegExmatch() or InStr() at the return of the function

Code: Select all

return (FocusedControlClass=Class)
Can become this

Code: Select all

return (FocusedControlClass ~= Class)
Basically the #if will be where you input your conditions and actions
But the #if is made true or false with the function that is bellow. Without the function the #if wont work because it will not be able to validate if its true or false. So dont miss that important part. The if is dependant on the fonction's return of true or false related to those things you want to validate

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 298 guests