Search found 429 matches

by ntepa
24 Apr 2024, 12:27
Forum: Ask for Help (v2)
Topic: KeyWait for multiple keys ?? Topic is solved
Replies: 8
Views: 310

Re: KeyWait for multiple keys ?? Topic is solved

Try this: Key_Wait_Multi(keys, &pressedKey?, options := "T2 V") { ih := InputHook("L1 " options) ih.KeyOpt(keys, "ES") ih.Start() ih.Wait() pressedKey := (StrLen(ih.EndKey) > 1) ? "{" ih.EndKey "}" : ih.EndKey return (ih.EndReason = "EndKey") } if Key_Wait_Multi("a{SC34}{F12}", &pressedKey) { Send(p...
by ntepa
18 Apr 2024, 22:29
Forum: Ask for Help (v2)
Topic: Can the Gui's close button be disabled Topic is solved
Replies: 6
Views: 176

Re: Can the Gui's close button be disabled Topic is solved

Return 1 on gui close:

Code: Select all

MyGui := Gui()
MyGui.OnEvent("Close", (*)=>1)
MyGui.Show("w200 h50")
by ntepa
16 Apr 2024, 16:12
Forum: Ask for Help (v2)
Topic: ListBox Enter pressed event?
Replies: 8
Views: 170

Re: ListBox Enter pressed event?

Another option: #Requires AutoHotkey v2.0 MyGui := Gui() MyListBox := MyGui.AddListBox(, ["red","green","blue"]) WM_KEYDOWN := 0x0100 OnMessage(WM_KEYDOWN, OnKeyDown) MyGui.Show() OnKeyDown(wParam, lParam, msg, hwnd) { key := GetKeyName(Format("VK{:x}", wParam)) if hwnd = MyListBox.hwnd && key = "En...
by ntepa
16 Apr 2024, 01:15
Forum: Ask for Help (v2)
Topic: Boilerplate current time Topic is solved
Replies: 6
Views: 153

Re: Boilerplate current time Topic is solved

Code: Select all

#Requires AutoHotkey v2.0 

:X*?:,time::SendText(FormatTime(, "HH:mm"))
by ntepa
14 Apr 2024, 19:03
Forum: Ask for Help (v2)
Topic: Get sc key code always for English keyboard
Replies: 3
Views: 70

Re: Get sc key code always for English keyboard

Try this: MsgBox "current language: " Format("sc{:x}", GetKeySC("/")) MsgBox "english: " Format("sc{:x}", GetKeySCFromLang("/")) ; Get SC key for keyboard layout, default is english. GetKeySCFromLang(key, langID := 0x4090409) { currentLayout := DllCall("GetKeyboardLayout", "uint", 0) ; Save previous...
by ntepa
13 Apr 2024, 20:27
Forum: Ask for Help (v2)
Topic: Hotkeys with RButton while keeping original function
Replies: 8
Views: 125

Re: Hotkeys with RButton while keeping original function

Try this: #Requires AutoHotkey v2.0 ; RButton keeps its original function. ~RButton:: ~RButton Up:: { ; If a hotkey is pressed between RButton and RButton up. if (A_PriorHotkey != "~RButton") { ; Send Esc to hide the right click menu. Send "{Esc}" } } #HotIf GetKeyState("RButton", "P") WheelRight::S...
by ntepa
10 Apr 2024, 04:13
Forum: Ask for Help (v2)
Topic: Can the newly added item be move to the top of a listbox and selected
Replies: 6
Views: 108

Re: Can the newly added item be move to the top of a listbox and selected

Another way using SendMessage: #Requires AutoHotkey v2.0 g := Gui() g.AddText(, "Add a new item:") myEdit := g.AddEdit("w150") g.AddButton("yp", "Enter").OnEvent("Click", AddItemToListBox) myListBox := g.AddListBox("xm r10 w200", ["apple", "orange", "banana"]) g.Show() AddItemToListBox(*) { LB_INSER...
by ntepa
09 Apr 2024, 17:55
Forum: Ask for Help (v2)
Topic: Issue with Building an Array Using a Loop Topic is solved
Replies: 10
Views: 280

Re: Issue with Building an Array Using a Loop Topic is solved

A valid array index needs to be less than or equal to the array length. Ier := [] creates an array with a length of 0. In the first iteration of the loop, it tries to set Ier[1] := [] . 1 is an invalid index because it's greater than Ier.length . You can set the length after creating Ier: #Requires ...
by ntepa
09 Apr 2024, 16:20
Forum: Ask for Help (v2)
Topic: "Expected a string, but got a function..."
Replies: 2
Views: 135

Re: "Expected a string, but got a function..."

Parentheses can be omitted only if the function is called by itself at the start of a line. There's also a missing comma between "click" and the fat arrow function. The space between them causes "click" to auto-concatenate with the fat arrow function. Strings cannot concatenate with functions, so it...
by ntepa
08 Apr 2024, 22:28
Forum: Bug Reports
Topic: [2.1-alpha.9] GuiControl.Prototype.OnMessage receives Gui in the callback's first parameter.
Replies: 0
Views: 85

[2.1-alpha.9] GuiControl.Prototype.OnMessage receives Gui in the callback's first parameter.

I expected the GuiOrCtrlObj parameter to be Gui if the callback was passed to Gui.Prototype.OnMessage or GuiControl if GuiControl.Prototype.OnMessage is used. Instead, I always get a Gui object. #Requires AutoHotkey v2.1-alpha.9 g := Gui() editCtrl := g.AddEdit("w200", "Edit") LV := g.AddListView("w...
by ntepa
08 Apr 2024, 16:08
Forum: Ask for Help (v2)
Topic: Is it possible to get the name of the instance of a class? Topic is solved
Replies: 2
Views: 101

Re: Is it possible to get the name of the instance of a class? Topic is solved

#Requires AutoHotkey v2.0 #SingleInstance MyFirstInstance := MyClass() MySecondInstance := MyClass() class MyClass { __new() { err := Error(, -2) ; Get call stack from Error object. stack := StrSplit(err.stack, "`n", "`r") ; In the first line of call stack, find one or more word characters, followe...
by ntepa
07 Apr 2024, 16:25
Forum: Ask for Help (v2)
Topic: 3-dimensional array and 4-dimensional array
Replies: 4
Views: 115

Re: 3-dimensional array and 4-dimensional array

That codes converts map to multidimensional map. The old code is too complicated. There's an easier way to convert it using Map.Prototype := MultiDimMap.Prototype . And if I need to use map to declare an associative array what I must make? See the bottom for an example: #Requires AutoHotkey v2.0 cla...
by ntepa
02 Apr 2024, 21:57
Forum: Ask for Help (v2)
Topic: How to avoid a hotkey being press more than twice Topic is solved
Replies: 10
Views: 155

Re: How to avoid a hotkey being press more than twice Topic is solved

#Requires AutoHotkey v2.0 F1::{ static myGui := CreateGui() myGui.Show() Hotkey "F1", "Off" HotIfWinNotExist "ahk_id" myGui.hwnd Hotkey "F1", (*) => myGui.Show(), "On" HotIf CreateGui() { local g g := Gui() g.Add('Radio', 'vMyRadioGroup', 'Option 1') g.Add('Radio', '', 'Option 2') g.Add('Radio', ''...
by ntepa
02 Apr 2024, 14:15
Forum: Ask for Help (v2)
Topic: How to avoid a hotkey being press more than twice Topic is solved
Replies: 10
Views: 155

Re: How to avoid a hotkey being press more than twice Topic is solved

Why destroy the gui instead of letting it hide? #Requires AutoHotkey v2.0 F1::{ static myGui myGui := Gui() myBtn := myGui.Add("Button", "Default w80", "F1_test") myBtn.OnEvent("Click", MyBtn_Click) myGui.Show("w100 h100") Hotkey("F1", "Off") HotIfWinNotExist "ahk_id" myGui.hwnd Hotkey("F1", (*) => ...
by ntepa
01 Apr 2024, 23:08
Forum: Ask for Help (v2)
Topic: Simple Hotkey question ?
Replies: 2
Views: 78

Re: Simple Hotkey question ?

Code: Select all

#Requires AutoHotkey v2.0

~<^RAlt::{
    KeyWait "LCtrl"
    if A_ThisHotkey = ThisHotkey {
        MsgBox("AltGr only")
    }
}

<^>!RButton::{
    MsgBox("<^>!RButton")
}
by ntepa
01 Apr 2024, 21:40
Forum: Ask for Help (v2)
Topic: How to avoid a hotkey being press more than twice Topic is solved
Replies: 10
Views: 155

Re: How to avoid a hotkey being press more than twice Topic is solved

If the hotkey also creates the gui, try this: F1::{ static myGui myGui := Gui() myGui.Show("w100 h100") Hotkey("F1", "Off") ; Disable the current hotkey HotIfWinNotExist "ahk_id" myGui.hwnd ; Create a new hotkey that shows the gui if it's not showing Hotkey("F1", (*) => myGui.Show("w100 h100"), "On"...
by ntepa
01 Apr 2024, 21:12
Forum: Ask for Help (v2)
Topic: How to avoid a hotkey being press more than twice Topic is solved
Replies: 10
Views: 155

Re: How to avoid a hotkey being press more than twice Topic is solved

Create a conditional hotkey using #HotIf?

Code: Select all

myGui := Gui()

#HotIf !WinActive(myGui)

    F1::myGui.Show("w100 h100")

#HotIf
by ntepa
31 Mar 2024, 23:34
Forum: Ask for Help (v2)
Topic: parse json into submenu and sub-sub menus in v2 Topic is solved
Replies: 9
Views: 186

Re: parse json into submenu and sub-sub menus in v2 Topic is solved

Try this: #include C:\hotkey\json.ahk ; Read the JSON file jsonContent := FileRead("C:\hotkey\myjson1.json") ; Parse the JSON content jsonObj := JSON.Load(jsonContent) m := Menu() objToMenu(jsonObj, m) objToMenu(obj, menuObj?) { if !IsSet(menuObj) menuObj := Menu() try enum := obj.__Enum(2) catch en...
by ntepa
30 Mar 2024, 18:42
Forum: Ask for Help (v2)
Topic: parse json into submenu and sub-sub menus in v2 Topic is solved
Replies: 9
Views: 186

Re: parse json into submenu and sub-sub menus in v2 Topic is solved

Try this: #include C:\hotkey\json.ahk ; Read the JSON file jsonContent := FileRead("C:\hotkey\myjson1.json") ; Parse the JSON content jsonObj := JSON.Load(jsonContent) m := Menu() objToMenu(jsonObj, m) objToMenu(obj, menuObj?) { if !IsSet(menuObj) menuObj := Menu() try enum := obj.__Enum(2) catch en...

Go to advanced search