Strange, but OK.
I combined mikeyww code with mine.
Change path of ini file to Yours
Then select any file, press f3
Hit your controller
after that You should see key name in inputbox
Press OK.
Hit your controller once again - file will open.
To delete key of you controller - select any file press f3, hit controller button that You want to delete, and write "DEL" before or after key in input box.
Code: Select all
Global ini := "D:\temp\mwMIDI.ini" ; Path to your INI file
setbatchlines -1
Global mode := ""
DllCall("LoadLibrary", "Str", "winmm.dll", "Ptr")
OnMessage(MIDI_OPEN := 0x3C1, "MidiInCallback")
OnMessage(MIDI_CLOSE := 0x3C2, "MidiInCallback")
OnMessage(MIDI_DATA := 0x3C3, "MidiInCallback")
OnMessage(MIDI_LONGDATA := 0x3C4, "MidiInCallback")
OnMessage(MIDI_ERROR := 0x3C5, "MidiInCallback")
OnMessage(MIDI_LONGERROR := 0x3C6, "MidiInCallback")
OnMessage(MIDI_MOREDATA := 0x3CC, "MidiInCallback")
OpenMidiIn()
return
#If WinActive("ahk_class Progman") or WinActive("ahk_class WorkerW") or WinActive("ahk_class CabinetWClass") or WinActive("ahk_class ExploreWClass")
F3:: ; Map the file to a string
file := Explorer_GetSelection().1 ; Get the path of file selected in Windows Explorer
if !file
{
msgbox file not selected
return
}
mode := "listen"
SplitPath, file, fn ; Get the file name
InputBox, newMidi, %fn%, Current mapping: %midi%`n`nEnter new mapping.,, 300, 125 ; Ask user for string assignment
if InStr(newMidi, "del")
{
newMidi := RegexReplace(newMidi, "[a-zA-Z\s]")
IniRead, file, %ini%, maps, %newMidi%
IniDelete, %ini%, maps, % newMidi ; Delete the assignment
MsgBox, 64, Deleted, % "Mapped: " file "`n`n To: " newMidi " [DELETED]"
}
else if (newMidi != "")
{
IniWrite, %file%, %ini%, maps, %newMidi% ; Save the assignment
{
If ErrorLevel
MsgBox, 48, Error, An error occurred during the mapping.
Else
MsgBox, 64, Changed, % "Mapped: " file "`n`n To: " newMidi
}
}
mode := ""
Return
#IfWinActive
OpenMidiIn()
{
count := DllCall("winmm.dll\midiOutGetNumDevs") - 1
if (count = 0)
{
msgbox no midi devices
exitapp
}
loop % count
{
id := A_Index-1
hr := DllCall("winmm.dll\midiInOpen", "ptr*", midiInHandle, "uint", id, "ptr", A_ScriptHwnd, "uint", 0, "uint", MIDI_CALLBACK_WINDOW := 0x10000)
if hr or ErrorLevel
{
Continue
msgbox % "midiInOpen error `nid = " id "`nhr = " hr "`nErrorLevel = " ErrorLevel
exitapp
}
hr := DllCall("winmm.dll\midiInStart", "ptr", midiInHandle)
if hr or ErrorLevel
{
Continue
msgbox % "midiInStart error `nid = " id "`nhr = " hr "`nErrorLevel = " ErrorLevel
exitapp
}
}
return
}
MidiInCallback(wParam, lParam, msg)
{
Critical
highByte := lParam & 0xF0
lowByte := lParam & 0x0F
data1 := (lParam >> 8) & 0xFF
data2 := (lParam >> 16) & 0xFF
if (data2 = 0)
return
key := highByte "-" lowByte "-" data1
if (mode = "listen")
{
ControlSetText, Edit1, % key, ahk_class #32770, Enter new mapping.
return
}
IniRead, file, %ini%, maps, %key% ; Find the assigned string that matches this file
If !(file ~= "ERROR|^$") ; An assigned string was found
Run, %file%
return
}
Explorer_GetSelection() {
; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256
array := []
WinGetClass, winClass, % "ahk_id " (hWnd := WinExist("A"))
If !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
Return
shellWindows := ComObjCreate("Shell.Application").Windows
If !(winClass ~= "Progman|WorkerW") {
For window in shellWindows
If (hWnd = window.HWND) && (shellFolderView := window.Document)
Break
} Else shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
For item in shellFolderView.SelectedItems
result .= (result = "" ? "" : "`n") . item.Path, array.Push(item.Path)
If !result
result := shellFolderView.Folder.Self.Path
Return array
}