How to assign a keyboard shortcut?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
huykiu23
Posts: 3
Joined: 27 Mar 2023, 23:12

How to assign a keyboard shortcut?

Post by huykiu23 » 27 Mar 2023, 23:16

Hello how to add this code to shortcut like
#`::WinSet, Transparent, 200, A
I need use it but i don't know how assign keyboard to use for my notepad.


[Mod action: Moved topic from an unrelated topic in “[V1] Scripts and Functions”]

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: How to assign a keyboard shortcut?

Post by mikeyww » 28 Mar 2023, 05:52

Welcome to this AutoHotkey forum!

Your script worked here.

When you press Win+`, the script adds the transparency to the active window.

huykiu23
Posts: 3
Joined: 27 Mar 2023, 23:12

Re: How to assign a keyboard shortcut?

Post by huykiu23 » 28 Mar 2023, 22:21

Thank for your reply

i found this viewtopic.php?t=63643

i want use it like winset transparent but i don't know how use it.

Code: Select all

#Persistent

CreateGui()
Gui, thisGuia: Show
Return

CreateGui() {

    thisFntSize := 25
    bgrColor := "000022"
    txtColor := "ffeedd"
    Gui, thisGuia: -DPIScale +Owner +hwndhGui
    Gui, thisGuia: Margin, % thisFntSize*2, % thisFntSize*2
    Gui, thisGuia: Color, c%bgrColor%
    Gui, thisGuia: Font, s%thisFntSize% Q5, Arial
    Gui, thisGuia: Add, Text, c%txtColor% , This is a demo. Enjoy.
    WinSet, AlwaysOnTop, On, ahk_id %hGui%
    SetAcrylicGlassEffect(bgrColor, 125, hGui)
}

ConvertToBGRfromRGB(RGB) { ; Get numeric BGR value from numeric RGB value or HTML color name
  ; HEX values
  BGR := SubStr(RGB, -1, 2) SubStr(RGB, 1, 4) 
  Return BGR 
}

SetAcrylicGlassEffect(thisColor, thisAlpha, hWindow) {
  ; based on https://github.com/jNizM/AHK_TaskBar_SetAttr/blob/master/scr/TaskBar_SetAttr.ahk
  ; by jNizM
    initialAlpha := thisAlpha
    If (thisAlpha<16)
       thisAlpha := 16
    Else If (thisAlpha>245)
       thisAlpha := 245


    thisColor := ConvertToBGRfromRGB(thisColor)
    thisAlpha := Format("{1:#x}", thisAlpha)
    gradient_color := thisAlpha . thisColor

    Static init, accent_state := 4, ver := DllCall("GetVersion") & 0xff < 10
    Static pad := A_PtrSize = 8 ? 4 : 0, WCA_ACCENT_POLICY := 19
    accent_size := VarSetCapacity(ACCENT_POLICY, 16, 0)
    NumPut(accent_state, ACCENT_POLICY, 0, "int")

    If (RegExMatch(gradient_color, "0x[[:xdigit:]]{8}"))
       NumPut(gradient_color, ACCENT_POLICY, 8, "int")

    VarSetCapacity(WINCOMPATTRDATA, 4 + pad + A_PtrSize + 4 + pad, 0)
    && NumPut(WCA_ACCENT_POLICY, WINCOMPATTRDATA, 0, "int")
    && NumPut(&ACCENT_POLICY, WINCOMPATTRDATA, 4 + pad, "ptr")
    && NumPut(accent_size, WINCOMPATTRDATA, 4 + pad + A_PtrSize, "uint")
    If !(DllCall("user32\SetWindowCompositionAttribute", "ptr", hWindow, "ptr", &WINCOMPATTRDATA))
       Return 0 
    thisOpacity := (initialAlpha<16) ? 60 + initialAlpha*9 : 250
    WinSet, Transparent, %thisOpacity%, ahk_id %hWindow%
    Return 1
}

thisGuiaGuiClose:
ExitApp
Return 

thisGuiaGuiEscape:
ExitApp
Return 

User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: How to assign a keyboard shortcut?

Post by mikeyww » 29 Mar 2023, 05:37

I am completely lost in this thread. Your subject is about a keyboard shortcut. You then asked a different question about a transparency command. You then asked a different question about a script that someone else wrote. I no longer know what problem you are having, or what the question is. If you have a question about the other post, I'm not sure why you didn't reply to it there. I have not used the other script that you cited. If you want to continue this thread, I recommend that you describe the problem that you are experiencing, and then ask a clear question about it. This will enable others to respond to it. No offense; I simply thought that your question was how to assign a keyboard shortcut to a command, but it looks like this is not actually the question, or looks like I have no idea what the question is. Best wishes for success!

Post Reply

Return to “Ask for Help (v1)”