one hotkey to use in several application for same task

Get help with using AutoHotkey and its commands and hotkeys
tatagi
Posts: 84
Joined: 23 Aug 2018, 11:17

one hotkey to use in several application for same task

08 Aug 2020, 02:15

I want to make script with hotkey that sends the same command in multiple application

for instance lik this

#ifwinactive, ahk_class Notepad
^lbutton::
send, {click}^a^c

#ifwinactive, ahk_class Chrome_WidgetWin_1
^lbutton::
send, {click}^a^c


this is just an example, so the script in real might be much more complex and longer.

but the concept is quite simple, is it possible to simply add all the application that is bound to this hotkey to the list? for the above example like this
(thought I have no clue it makes any sense)

#ifwinactive, ahk_class Notepad & ahk_class Chrome_WidgetWin_1
^lbutton::
send, {click}^a^c

that & should mean "or" so I just got an example.



thanks. probably I am not well skilled searcher or asking for something not realizable. :salute:
BoBo
Posts: 3642
Joined: 13 May 2014, 17:15

Re: one hotkey to use in several application for same task

08 Aug 2020, 05:10

Code: Select all

#ifwinactive, ahk_class Notepad
^lbutton::send, {click}^a^c    ; single line hotkey

#ifwinactive, ahk_class Chrome_WidgetWin_1
^lbutton::send, {click}^a^c

#ifwinactive ("ahk_class Notepad" || "ahk_class Chrome_WidgetWin_1")    ; no idea if this OR-condition using a forced expression is working for you?
^lbutton::
        send, {click}^a^c
        Return        ; used with multiline hotkeys!
#If
HTH.
Rohwedder
Posts: 3385
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: one hotkey to use in several application for same task

08 Aug 2020, 05:12

Hallo,
try:

Code: Select all

#If WinActive("ahk_class Notepad") Or WinActive("ahk_class Chrome_WidgetWin_1")
^lbutton::send, {click}^a^c
#If
Or use https://www.autohotkey.com/docs/commands/GroupAdd.htm

Code: Select all

GroupAdd, GroupName, ahk_class Notepad
GroupAdd, GroupName, ahk_class Chrome_WidgetWin_1
Return
#IfWinActive ahk_group GroupName
^lbutton::send, {click}^a^c
#If
tatagi
Posts: 84
Joined: 23 Aug 2018, 11:17

Re: one hotkey to use in several application for same task

08 Aug 2020, 17:19

thank you for the answer both :) I tested it out and the script itself works flawlessly

but there's something I probably missed or did wrong in my entire script, please take a look a this.

Code: Select all

#if, getkeystate("capslock", "p")

IME_CHECK(WinTitle)                             ;Language change

{
    WinGet,hWnd,ID,%WinTitle%
    Return Send_ImeControl(ImmGetDefaultIMEWnd(hWnd),0x005,"")
}
Send_ImeControl(DefaultIMEWnd, wParam, lParam)
{
    DetectSave := A_DetectHiddenWindows       
    DetectHiddenWindows,ON                           

     SendMessage 0x283, wParam,lParam,,ahk_id %DefaultIMEWnd%
    if (DetectSave <> A_DetectHiddenWindows)
        DetectHiddenWindows,%DetectSave%
    return ErrorLevel
}

ImmGetDefaultIMEWnd(hWnd)
{
    return DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
}

q::                                     ;to korean
sleep 50
    ret := ime_check("a")
    if %ret% = 0               
    {
        send, {vk15}           
    }
return

w::                                   ;to english
sleep 50
    ret := ime_check("a")
    if %ret% <> 0           
    {
        send, {vk15}          
    }
return

lbutton::                       ;to korean
send, {click}^a
sleep 50
    ret := ime_check("a")
    if %ret% = 0
    {
        send, {vk15}
    }
return

rbutton::                      ;to english
send, {click}^a
sleep 50
    ret := ime_check("a")
    if %ret% <> 0
    {
        send, {vk15}
    }
return



And I want to have this done.
when I press capslock + lbutton, it should send:

Code: Select all

send, {click}
sleep 50
    ret := ime_check("a")
    if %ret% = 0
    {
        send, {vk15}
    }
And when I press capslock + rbutton, it should send:

Code: Select all

send, {click}
sleep 50
    ret := ime_check("a")
    if %ret% <> 0
    {
        send, {vk15}
    }

only when either of these programs are active; Notepad or Chrome_WidgetWin_1, or any programs as I choose, and other than those programs, the same hotkey's supposed to do a bit different task.
so I implemented you two's script into mine, but none succeeded. please have a look.

For example:

Code: Select all

#if, getkeystate("capslock", "p")

IME_CHECK(WinTitle)                             ;Language change

{
    WinGet,hWnd,ID,%WinTitle%
    Return Send_ImeControl(ImmGetDefaultIMEWnd(hWnd),0x005,"")
}
Send_ImeControl(DefaultIMEWnd, wParam, lParam)
{
    DetectSave := A_DetectHiddenWindows       
    DetectHiddenWindows,ON                           

     SendMessage 0x283, wParam,lParam,,ahk_id %DefaultIMEWnd%
    if (DetectSave <> A_DetectHiddenWindows)
        DetectHiddenWindows,%DetectSave%
    return ErrorLevel
}

ImmGetDefaultIMEWnd(hWnd)
{
    return DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
}

q::                                     ;to korean
sleep 50
    ret := ime_check("a")
    if %ret% = 0               
    {
        send, {vk15}           
    }
return

w::                                   ;to english
sleep 50
    ret := ime_check("a")
    if %ret% <> 0           
    {
        send, {vk15}          
    }
return

#If WinActive("ahk_class Notepad") Or WinActive("ahk_class Chrome_WidgetWin_1")
lbutton::
send, {click}
sleep 50
    ret := ime_check("a")
    if %ret% = 0
    {
        send, {vk15}
    }
else
send, {click}^a
sleep 50
    ret := ime_check("a")
    if %ret% = 0
    {
        send, {vk15}
    }

rbutton::
send, {click}
sleep 50
    ret := ime_check("a")
    if %ret% <> 0
    {
        send, {vk15}
    }
else
send, {click}^a
sleep 50
    ret := ime_check("a")
    if %ret% <> 0
    {
        send, {vk15}
    }
#If
I think there's something wrong with my use of Sharp, Bracket or something, that this script is not working as I expected.
any additional idea? thank you so much!
Last edited by tatagi on 08 Aug 2020, 21:59, edited 1 time in total.
Rohwedder
Posts: 3385
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: one hotkey to use in several application for same task

09 Aug 2020, 01:06

So replace #If WinActive("ahk_class Notepad") Or WinActive("ahk_class Chrome_WidgetWin_1")
by:

Code: Select all

#If GetKeyState("capslock", "p")
And WinActive("ahk_class Notepad")
Or WinActive("ahk_class Chrome_WidgetWin_1")

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], boiler, Google [Bot], hasantr, jadams, mikeyww and 60 guests