![Waving :wave:](./images/smilies/icon_wave.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
OK, you inspired me to go get a 32-key MIDI controller. It will take me about a week to figure this out!
Ok, that's a specific command i can follow! Yeh!
Code: Select all
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
f1::
mode := "listen"
; some code
mode := ""
return
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
{
msgbox % "midiInOpen error `nid = " id "`nhr = " hr "`nErrorLevel = " ErrorLevel
exitapp
}
hr := DllCall("winmm.dll\midiInStart", "ptr", midiInHandle)
if hr or ErrorLevel
{
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")
{
msgbox % "listen`n" key
return
}
; here get info from ini file if key exist then run its value
msgbox % "run`n" key
return
}
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
}
Code: Select all
Global ini := "D:\test.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. errorlevel - %errorlevel%
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
}
Users browsing this forum: Bing [Bot], Chunjee and 368 guests