Compare commits

..

10 Commits

Author SHA1 Message Date
Laurence Dougal Myers 2006cd1db1 #5: Fix pitch bend values not being set, by making pitchb a global variable (just like byte1 and byte2). 2024-01-23 23:55:28 +11:00
Laurence Dougal Myers c726e1280a MidiMon: the MIDI input dropdown will now automatically reload the script. 2023-12-19 18:16:13 +11:00
Laurence Dougal Myers 2cb4e30b0f Remove UserVariables.ahk, it didn't serve a purpose 2023-12-19 17:40:17 +11:00
Laurence Dougal Myers 7dbfa98008 Add a README.md 2020-08-29 12:50:17 +10:00
Laurence Dougal Myers 1f829dd568 Remove MIDI Out functionality 2020-08-29 12:25:17 +10:00
Laurence Dougal Myers aacb44c7a8 - Remove vjoy functionality
- Rename files for consistency
- Fix accidental creation of both *.ini and *io.ini files
- Change hardcoded "version" so that the ini file is called `MidiToMacro.ini`
2020-08-29 12:00:46 +10:00
Laurence Dougal Myers c2f678893d Convert .hgignore to .gitignore 2020-08-29 11:37:24 +10:00
Laurence Dougal Myers de4b06a8b6 CC 58: Place a cue marker in Sound Forge 9 2018-12-02 19:30:56 +11:00
Laurence Dougal Myers 5e06493275 Media control script 2014-06-25 22:38:28 +10:00
Laurence Dougal Myers 33da05e5e9 Only convert MIDI port names to UTF-8 if running in Unicode mode. 2014-01-27 17:12:27 +11:00
17 changed files with 685 additions and 2366 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.bak
*.ini

View File

@ -1,2 +0,0 @@
syntax: glob
*.bak

View File

@ -12,7 +12,7 @@
MidiMsgDetect(hInput, midiMsg, wMsg) ; Midi input section in "under the hood" calls this function each time a midi message is received. Then the midi message is broken up into parts for manipulation. See http://www.midi.org/techspecs/midimessages.php (decimal values). MidiMsgDetect(hInput, midiMsg, wMsg) ; Midi input section in "under the hood" calls this function each time a midi message is received. Then the midi message is broken up into parts for manipulation. See http://www.midi.org/techspecs/midimessages.php (decimal values).
{ {
global statusbyte, chan, note, cc, byte1, byte2, stb global statusbyte, chan, note, cc, byte1, byte2, pitchb, stb
statusbyte := midiMsg & 0xFF ; EXTRACT THE STATUS BYTE (WHAT KIND OF MIDI MESSAGE IS IT?) statusbyte := midiMsg & 0xFF ; EXTRACT THE STATUS BYTE (WHAT KIND OF MIDI MESSAGE IS IT?)
chan := (statusbyte & 0x0f) + 1 ; WHAT MIDI CHANNEL IS THE MESSAGE ON? chan := (statusbyte & 0x0f) + 1 ; WHAT MIDI CHANNEL IS THE MESSAGE ON?
@ -85,9 +85,7 @@ midiMon: ; midi monitor gui with listviews
gui,14:destroy gui,14:destroy
gui,14:default gui,14:default
gui,14:add,text, x80 y5, Midi Input ; %TheChoice% gui,14:add,text, x80 y5, Midi Input ; %TheChoice%
Gui,14:Add, DropDownList, x40 y20 w140 Choose%TheChoice% vMidiInPort gDoneInChange altsubmit, %MiList% ; ( Gui,14:Add, DropDownList, x40 y20 w140 Choose%TheChoice% vMidiInPort gOnMidiMonInputChange altsubmit, %MiList% ; (
gui,14:add,text, x305 y5, Midi Ouput ; %TheChoice2%
Gui,14:Add, DropDownList, x270 y20 w140 Choose%TheChoice2% vMidiOutPort gDoneOutChange altsubmit , %MoList%
Gui,14:Add, ListView, x5 r11 w220 Backgroundblack caqua Count10 vIn1, EventType|StatB|Ch|Byte1|Byte2| Gui,14:Add, ListView, x5 r11 w220 Backgroundblack caqua Count10 vIn1, EventType|StatB|Ch|Byte1|Byte2|
gui,14:Add, ListView, x+5 r11 w220 Backgroundblack cyellow Count10 vOut1, Event|Value| gui,14:Add, ListView, x+5 r11 w220 Backgroundblack cyellow Count10 vOut1, Event|Value|
LV_ModifyCol(1, 105) LV_ModifyCol(1, 105)
@ -96,24 +94,12 @@ gui,14:Show, autosize xcenter y5, MidiMonitor
Return Return
OnMidiMonInputChange:
;************************************************* Gui, Submit, NoHide
;* MIDI OUTPUT LABELS TO CALL If %MidiInPort%
;************************************************* MidiInDevice := MidiInPort - 1
WriteIni()
SendNote: ;(h_midiout,Note) ; send out note messages ; this should probably be a funciton Reload
note = %byte1% ; this var is added to allow transpostion of a note
midiOutShortMsg(h_midiout, statusbyte, note, byte2) ; call the midi funcitons with these params.
gosub, ShowMidiOutMessage
Return
SendCC:
midiOutShortMsg(h_midiout, statusbyte, cc, byte2)
Return
SendPC:
gosub, ShowMidiOutMessage
midiOutShortMsg(h_midiout, statusbyte, pc, byte2)
Return Return
; MIDI Rules dispatcher ; MIDI Rules dispatcher

View File

@ -9,27 +9,40 @@
*/ */
ProcessNote(device, channel, note, velocity, isNoteOn) { ProcessNote(device, channel, note, velocity, isNoteOn) {
global iInterface
if (note >= 1 and note <= 32) {
VJoy_SetBtn(isNoteOn, iInterface, note)
button_state_text := isNoteOn ? "On" : "Off"
DisplayOutput("Button " + button_state_text, note)
}
} }
ProcessCC(device, channel, cc, value) { ProcessCC(device, channel, cc, value) {
global iInterface, HID_USAGE_X, HID_USAGE_Y, AxisMax_X, AxisMax_Y if (cc = 21 or cc = 29) {
if (cc == 7) { scaled_value := ConvertCCValueToScale(value, 0, 127)
scaled_value := ConvertCCValueToScale(value, 8, 120) vol := scaled_value * 100
new_axis_value := ConvertToAxis(scaled_value, AxisMax_X) SoundSet, vol
VJoy_SetAxis(new_axis_value, iInterface, HID_USAGE_X) DisplayOutput("Volume", vol)
DisplayOutput("Axis X", scaled_value) } else if (cc = 51) {
} else if (cc == 27) { Send {Volume_Mute}
scaled_value := ConvertCCValueToScale(value, 8, 112) DisplayOutput("Volume", "Mute")
new_axis_value := ConvertToAxis(scaled_value, AxisMax_Y) } else if (cc = 52 and value != 0) {
VJoy_SetAxis(new_axis_value, iInterface, HID_USAGE_Y) Send {Volume_Down}
DisplayOutput("Axis Y", scaled_value) DisplayOutput("Volume", "Down")
} else if (cc = 53 and value != 0) {
Send {Volume_Up}
DisplayOutput("Volume", "Up")
} else if (cc = 54 and value != 0) {
Send {Media_Play_Pause}
DisplayOutput("Media", "Play/Pause")
} else if (cc = 55 and value != 0) {
Send {Media_Stop}
DisplayOutput("Media", "Stop")
} else if (cc = 56 and value != 0) {
Send {Media_Prev}
DisplayOutput("Media", "Previous")
} else if (cc = 57 and value != 0) {
Send {Media_Next}
DisplayOutput("Media", "Next")
} else if (cc = 58 and value != 0) {
; Place a cue marker in Sound Forge 9
ControlSend, , {Alt down}m{Alt up}, ahk_class #32770
DisplayOutput("Sound Forge", "Place Cue Marker")
} }
} }

View File

@ -14,8 +14,8 @@ Sections with ++++++++++++++++++++ Edit between these marks. You won't break it,
*/ */
#Include VJoy_lib.ahk
#Include mtjFunctions.ahk #Include CommonFunctions.ahk
#Persistent #Persistent
#SingleInstance #SingleInstance
@ -28,37 +28,16 @@ if A_OSVersion in WIN_NT4,WIN_95,WIN_98,WIN_ME ; if not xp or 2000 quit
ExitApp ExitApp
} }
version = midi_to_joy_2 version = MidiToMacro
VJoy_Init()
gosub VJoyInitMaxValues
readini() ; load values from the ini file, via the readini function - see Midi_under_the_hood.ahk file readini() ; load values from the ini file, via the readini function - see Midi_under_the_hood.ahk file
gosub, MidiPortRefresh ; used to refresh the input and output port lists - see Midi_under_the_hood.ahk file gosub, MidiPortRefresh ; used to refresh the input and output port lists - see Midi_under_the_hood.ahk file
port_test(numports,numports2) ; test the ports - check for valid ports? - see Midi_under_the_hood.ahk file port_test(numports,numports2) ; test the ports - check for valid ports? - see Midi_under_the_hood.ahk file
gosub, midiin_go ; opens the midi input port listening routine see Midi_under_the_hood.ahk file gosub, midiin_go ; opens the midi input port listening routine see Midi_under_the_hood.ahk file
gosub, midiout ; opens the midi out port see Midi_under_the_hood.ahk file
gosub, midiMon ; see below - a monitor gui - see Midi_In_and_GuiMonitor.ahk gosub, midiMon ; see below - a monitor gui - see Midi_In_and_GuiMonitor.ahk
;*************************************************
;* VARIBLES TO SET @ STARTUP
;*************************************************
#Include UserVariables.ahk
return return
VJoyInitMaxValues:
global AxisMax_X, AxisMax_Y, AxisMax_Z, AxisMax_RX, AxisMax_RY, AxisMax_RZ, AxisMax_SL0, AxisMax_SL1, AxisMax_WHL
AxisMax_X := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_X)
AxisMax_Y := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_Y)
AxisMax_Z := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_Z)
AxisMax_RX := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RX)
AxisMax_RY := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RY)
AxisMax_RZ := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RZ)
AxisMax_SL0 := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_SL0)
AxisMax_SL1 := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_SL1)
AxisMax_WHL := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_WHL)
return
#Include Midi_In_and_GuiMonitor.ahk ; this file contains: the function to parse midi message into parts we can work with and a midi monitor. #Include MidiInAndGuiMonitor.ahk ; this file contains: the function to parse midi message into parts we can work with and a midi monitor.
#Include MidiRules.ahk ; this file contains: Rules for manipulating midi input then sending modified midi output. #Include MidiRules.ahk ; this file contains: Rules for manipulating midi input then sending modified midi output.
#Include Midi_under_the_hood.ahk ; this file contains: (DO NOT EDIT THIS FILE) all the dialogs to set up midi ports and midi message handling. #Include MidiUnderTheHood.ahk ; this file contains: (DO NOT EDIT THIS FILE) all the dialogs to set up midi ports and midi message handling.

View File

@ -39,12 +39,6 @@ MidiPortRefresh: ; get the list of ports
} }
TheChoice := MidiInDevice + 1 TheChoice := MidiInDevice + 1
MOlist := MidiOutsList(NumPorts2)
Loop Parse, MOlist, |
{
}
TheChoice2 := MidiOutDevice + 1
return return
;************************************************* ;*************************************************
@ -57,11 +51,10 @@ ReadIni() ; also set up the tray Menu
Menu, tray, add, MidiSet ; set midi ports tray item Menu, tray, add, MidiSet ; set midi ports tray item
Menu, tray, add, ResetAll ; Delete the ini file for testing -------------------------------- Menu, tray, add, ResetAll ; Delete the ini file for testing --------------------------------
menu, tray, add, MidiMon menu, tray, add, MidiMon
global MidiInDevice, MidiOutDevice, version ; version var is set at the beginning. global MidiInDevice, version ; version var is set at the beginning.
IfExist, %version%.ini IfExist, %version%.ini
{ {
IniRead, MidiInDevice, %version%.ini, Settings, MidiInDevice , %MidiInDevice% ; read the midi In port from ini file IniRead, MidiInDevice, %version%.ini, Settings, MidiInDevice , %MidiInDevice% ; read the midi In port from ini file
IniRead, MidiOutDevice, %version%.ini, Settings, MidiOutDevice , %MidiOutDevice% ; read the midi out port from ini file
} }
Else ; no ini exists and this is either the first run or reset settings. Else ; no ini exists and this is either the first run or reset settings.
{ {
@ -80,12 +73,11 @@ ReadIni() ; also set up the tray Menu
;CALLED TO UPDATE INI WHENEVER SAVED PARAMETERS CHANGE ;CALLED TO UPDATE INI WHENEVER SAVED PARAMETERS CHANGE
WriteIni() WriteIni()
{ {
global MidiInDevice, MidiOutDevice, version global MidiInDevice, version
IfNotExist, %version%io.ini ; if no ini IfNotExist, %version%.ini ; if no ini
FileAppend,, %version%io.ini ; make one with the following entries. FileAppend,, %version%.ini ; make one with the following entries.
IniWrite, %MidiInDevice%, %version%.ini, Settings, MidiInDevice IniWrite, %MidiInDevice%, %version%.ini, Settings, MidiInDevice
IniWrite, %MidiOutDevice%, %version%.ini, Settings, MidiOutDevice
} }
;************************************************* ;*************************************************
@ -96,7 +88,7 @@ WriteIni()
port_test(numports,numports2) ; confirm selected ports exist ; CLEAN THIS UP STILL port_test(numports,numports2) ; confirm selected ports exist ; CLEAN THIS UP STILL
{ {
global midiInDevice, midiOutDevice, midiok global midiInDevice, midiok
; ----- In port selection test based on numports ; ----- In port selection test based on numports
If MidiInDevice not Between 0 and %numports% If MidiInDevice not Between 0 and %numports%
@ -114,26 +106,9 @@ port_test(numports,numports2) ; confirm selected ports exist ; CLEAN THIS UP STI
{ {
MidiIn := 1 ; setting var to non-error state or valid MidiIn := 1 ; setting var to non-error state or valid
} }
; ----- out port selection test based on numports2 If (%MidiIn% = 0)
If MidiOutDevice not Between 0 and %numports2%
{ {
MidiOut := 0 ; set var to 0 as Error state. MsgBox, 49, Midi Port Error!,%MidiInerr%`n`nLaunch Midi Port Selection!
If (MidiOutDevice = "") ; if blank
MidiOuterr = Midi Out Port EMPTY. ; set this error message
;MsgBox, 0, , midi o port EMPTY
If (midiOutDevice > %numports2%) ; if greater than number of availble ports
MidiOuterr = Midi Out Port Out Invalid. ; set this error message
;MsgBox, 0, , midi out port out of range
}
Else
{
MidiOut := 1 ;set var to 1 as valid state.
}
; ---- test to see if ports valid, if either invalid load the gui to select.
;midicheck(MCUin,MCUout)
If (%MidiIn% = 0) Or (%MidiOut% = 0)
{
MsgBox, 49, Midi Port Error!,%MidiInerr%`n%MidiOuterr%`n`nLaunch Midi Port Selection!
IfMsgBox, Cancel IfMsgBox, Cancel
ExitApp ExitApp
midiok = 0 ; Not sure if this is really needed now.... midiok = 0 ; Not sure if this is really needed now....
@ -170,11 +145,6 @@ MidiSet: ; midi port selection gui
Gui, 4: Add, ListBox, x10 w200 h100 Choose%TheChoice% vMidiInPort gDoneInChange AltSubmit, %MiList% ; --- midi in listing of ports Gui, 4: Add, ListBox, x10 w200 h100 Choose%TheChoice% vMidiInPort gDoneInChange AltSubmit, %MiList% ; --- midi in listing of ports
;Gui, Add, DropDownList, x10 w200 h120 Choose%TheChoice% vMidiInPort gDoneInChange altsubmit, %MiList% ; ( you may prefer this style, may need tweak) ;Gui, Add, DropDownList, x10 w200 h120 Choose%TheChoice% vMidiInPort gDoneInChange altsubmit, %MiList% ; ( you may prefer this style, may need tweak)
; --------------- MidiOutSet ---------------------
Gui, 4: Add, TEXT, x220 y40 w175 Center, Midi Out Port ; gDoneOutChange
; midi outlist box
Gui, 4: Add, ListBox, x220 y62 w200 h100 Choose%TheChoice2% vMidiOutPort gDoneOutChange AltSubmit, %MoList% ; --- midi out listing
;Gui, Add, DropDownList, x220 y97 w200 h120 Choose%TheChoice2% vMidiOutPort gDoneOutChange altsubmit , %MoList%
Gui, 4: add, Button, x10 w205 gSet_Done, Done - Reload script. Gui, 4: add, Button, x10 w205 gSet_Done, Done - Reload script.
Gui, 4: add, Button, xp+205 w205 gCancel, Cancel Gui, 4: add, Button, xp+205 w205 gCancel, Cancel
;gui, 4: add, checkbox, x10 y+10 vNotShown gDontShow, Do Not Show at startup. ;gui, 4: add, checkbox, x10 y+10 vNotShown gDontShow, Do Not Show at startup.
@ -204,20 +174,6 @@ DoneInChange:
;MsgBox, 32, , midi in device = %MidiInDevice%`nmidiinport = %MidiInPort%`nport = %port%`ndevice= %device% `n UDPort = %UDport% ; only for testing ;MsgBox, 32, , midi in device = %MidiInDevice%`nmidiinport = %MidiInPort%`nport = %port%`ndevice= %device% `n UDPort = %UDport% ; only for testing
Return Return
DoneOutChange:
gui +lastfound
Gui, Submit, NoHide
Gui, Flash
Gui, 4: Submit, NoHide
Gui, 4: Flash
If %MidiOutPort%
UDPort2:= MidiOutPort - 1 , MidiOutDevice:= UDPort2
GuiControl, 4: , UDPort2, %MidiOutdevice%
WriteIni()
;Gui, Destroy
Return
;------------------------ end of the doneout change stuff. ;------------------------ end of the doneout change stuff.
Set_Done: ; aka reload program, called from midi selection gui Set_Done: ; aka reload program, called from midi selection gui
@ -240,11 +196,6 @@ Return
;************************************************* ;*************************************************
; ********************** Midi output detection ; ********************** Midi output detection
MidiOut: ; Function to load new settings from midi out menu item
OpenCloseMidiAPI()
h_midiout := midiOutOpen(MidiOutDevice) ; OUTPUT PORT 1 SEE BELOW FOR PORT 2
return
ResetAll: ; for development only, leaving this in for a program reset if needed by user ResetAll: ; for development only, leaving this in for a program reset if needed by user
MsgBox, 33, %version% - Reset All?, This will delete ALL settings`, and restart this program! MsgBox, 33, %version% - Reset All?, This will delete ALL settings`, and restart this program!
IfMsgBox, OK IfMsgBox, OK
@ -261,8 +212,6 @@ GuiClose: ; on x exit app
MsgBox, 4, Exit %version%, Exit %version% %ver%? ; MsgBox, 4, Exit %version%, Exit %version% %ver%? ;
IfMsgBox No IfMsgBox No
Return Return
Else IfMsgBox Yes
midiOutClose(h_midiout)
Gui, 6: Destroy Gui, 6: Destroy
Gui, 2: Destroy Gui, 2: Destroy
@ -355,7 +304,9 @@ MidiInsList(ByRef NumPorts)
Continue Continue
} }
DllCall("RtlMoveMemory", Str,PortName, UInt,&MidiInCaps+8, UInt,PortNameSize) ; PortNameOffset 8, PortNameSize 32 DllCall("RtlMoveMemory", Str,PortName, UInt,&MidiInCaps+8, UInt,PortNameSize) ; PortNameOffset 8, PortNameSize 32
if (A_IsUnicode) {
PortName := Strget(&PortName, "UTF-8") PortName := Strget(&PortName, "UTF-8")
}
List .= "|" PortName List .= "|" PortName
} }
Return SubStr(List,2) Return SubStr(List,2)
@ -389,7 +340,9 @@ MidiInNameGet(uDeviceID = 0) { ; Get name of a midiOut device for a given ID
VarSetCapacity(PortName, PortNameSize) VarSetCapacity(PortName, PortNameSize)
DllCall("RtlMoveMemory", Str,PortName, Uint,&MidiInCaps+OffsettoPortName, Uint,PortNameSize) DllCall("RtlMoveMemory", Str,PortName, Uint,&MidiInCaps+OffsettoPortName, Uint,PortNameSize)
if (A_IsUnicode) {
PortName := Strget(&PortName, "UTF-8") PortName := Strget(&PortName, "UTF-8")
}
Return PortName Return PortName
} }
@ -405,46 +358,6 @@ MidiInsEnumerate() { ; Returns number of midi output devices, creates global arr
Return NumPorts Return NumPorts
} }
;*************************************************
;* MIDI OUT LIBRARY FROM lASZLO/TOMB
; Modified by JimF - removed long message
; handling as well as combining status byte with ch
; see commented out section below if you want to change it back
;*************************************************
; =============== end of midi selection stuff
MidiOutsList(ByRef NumPorts)
{ ; Returns a "|"-separated list of midi output devices
local List, MidiOutCaps, PortName, result
PortNameSize := 32 * (A_IsUnicode ? 2 : 1)
VarSetCapacity(MidiOutCaps, 50, 0)
VarSetCapacity(PortName, PortNameSize) ; PortNameSize 32
NumPorts := DllCall("winmm.dll\midiOutGetNumDevs") ; #midi output devices on system, First device ID = 0
Loop %NumPorts%
{
result := DllCall("winmm.dll\midiOutGetDevCapsA", UInt,A_Index-1, UInt,&MidiOutCaps, UInt,50, UInt)
If (result OR ErrorLevel)
{
List .= "|-Error-"
Continue
}
DllCall("RtlMoveMemory", Str,PortName, UInt,&MidiOutCaps+8, UInt,PortNameSize) ; PortNameOffset 8, PortNameSize 32
PortName := Strget(&PortName, "UTF-8")
List .= "|" PortName
}
Return SubStr(List,2)
}
;---------------------midiOut from TomB and Lazslo and JimF --------------------------------
;THATS THE END OF MY STUFF (JimF) THE REST ID WHAT LASZLo AND PAXOPHONE WERE USING ALREADY
;AHK FUNCTIONS FOR MIDI OUTPUT - calling winmm.dll
;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_multimedia_functions.asp
;Derived from Midi.ahk dated 29 August 2008 - streaming support removed - (JimF)
OpenCloseMidiAPI() { ; at the beginning to load, at the end to unload winmm.dll OpenCloseMidiAPI() { ; at the beginning to load, at the end to unload winmm.dll
static hModule static hModule
If hModule If hModule
@ -455,107 +368,6 @@ OpenCloseMidiAPI() { ; at the beginning to load, at the end to unload winmm.dll
} }
} }
;FUNCTIONS FOR SENDING SHORT MESSAGES
midiOutOpen(uDeviceID = 0) { ; Open midi port for sending individual midi messages --> handle
strh_midiout = 0000
result := DllCall("winmm.dll\midiOutOpen", UInt,&strh_midiout, UInt,uDeviceID, UInt,0, UInt,0, UInt,0, UInt)
If (result or ErrorLevel) {
MsgBox There was an Error opening the midi port.`nError code %result%`nErrorLevel = %ErrorLevel%
Return -1
}
Return UInt@(&strh_midiout)
}
midiOutShortMsg(h_midiout, MidiStatus, Param1, Param2) { ;Channel,
;h_midiout: handle to midi output device returned by midiOutOpen
;EventType, Channel combined -> MidiStatus byte: http://www.harmony-central.com/MIDI/Doc/table1.html
;Param3 should be 0 for PChange, ChanAT, or Wheel
;Wheel events: entire Wheel value in Param2 - the function splits it into two bytes
/*
If (EventType = "NoteOn" OR EventType = "N1")
MidiStatus := 143 + Channel
Else If (EventType = "NoteOff" OR EventType = "N0")
MidiStatus := 127 + Channel
Else If (EventType = "CC")
MidiStatus := 175 + Channel
Else If (EventType = "PolyAT" OR EventType = "PA")
MidiStatus := 159 + Channel
Else If (EventType = "ChanAT" OR EventType = "AT")
MidiStatus := 207 + Channel
Else If (EventType = "PChange" OR EventType = "PC")
MidiStatus := 191 + Channel
Else If (EventType = "Wheel" OR EventType = "W") {
MidiStatus := 223 + Channel
Param2 := Param1 >> 8 ; MSB of wheel value
Param1 := Param1 & 0x00FF ; strip MSB
}
*/
result := DllCall("winmm.dll\midiOutShortMsg", UInt,h_midiout, UInt, MidiStatus|(Param1<<8)|(Param2<<16), UInt)
If (result or ErrorLevel) {
MsgBox There was an Error Sending the midi event: (%result%`, %ErrorLevel%)
Return -1
}
}
midiOutClose(h_midiout) { ; Close MidiOutput
Loop 9 {
result := DllCall("winmm.dll\midiOutClose", UInt,h_midiout)
If !(result or ErrorLevel)
Return
Sleep 250
}
MsgBox Error in closing the midi output port. There may still be midi events being Processed.
Return -1
}
;UTILITY FUNCTIONS
MidiOutGetNumDevs() { ; Get number of midi output devices on system, first device has an ID of 0
Return DllCall("winmm.dll\midiOutGetNumDevs")
}
MidiOutNameGet(uDeviceID = 0) { ; Get name of a midiOut device for a given ID
;MIDIOUTCAPS struct
; WORD wMid;
; WORD wPid;
; MMVERSION vDriverVersion;
; CHAR szPname[MAXPNAMELEN];
; WORD wTechnology;
; WORD wVoices;
; WORD wNotes;
; WORD wChannelMask;
; DWORD dwSupport;
VarSetCapacity(MidiOutCaps, 50, 0) ; allows for szPname to be 32 bytes
OffsettoPortName := 8
PortNameSize := 32 * (A_IsUnicode ? 2 : 1)
result := DllCall("winmm.dll\midiOutGetDevCapsA", UInt,uDeviceID, UInt,&MidiOutCaps, UInt,50, UInt)
If (result OR ErrorLevel) {
MsgBox Error %result% (ErrorLevel = %ErrorLevel%) in retrieving the name of midi output %uDeviceID%
Return -1
}
VarSetCapacity(PortName, PortNameSize)
DllCall("RtlMoveMemory", Str,PortName, Uint,&MidiOutCaps+OffsettoPortName, Uint,PortNameSize)
PortName := Strget(&PortName, "UTF-8")
Return PortName
}
MidiOutsEnumerate() { ; Returns number of midi output devices, creates global array MidiOutPortName with their names
local NumPorts, PortID
MidiOutPortName =
NumPorts := MidiOutGetNumDevs()
Loop %NumPorts% {
PortID := A_Index -1
MidiOutPortName%PortID% := MidiOutNameGet(PortID)
}
Return NumPorts
}
UInt@(ptr) { UInt@(ptr) {
Return *ptr | *(ptr+1) << 8 | *(ptr+2) << 16 | *(ptr+3) << 24 Return *ptr | *(ptr+1) << 8 | *(ptr+2) << 16 | *(ptr+3) << 24
} }

89
README.md Normal file
View File

@ -0,0 +1,89 @@
# MidiToMacro
This is an AutoHotKey script for Windows, to map MIDI input values to hotkeys or macros.
You can use this script to bind CC messages to media keys (play/pause/next), volume sliders, or unusual keyboard combinations (ctrl+shift+alt+F13) which you can assign in programs like StreamLabs OBS.
It's cobbled together from scripts found on the AHK forums. It originally supported mapping MIDI inputs to a virtual joystick using vJoy, and to MIDI outputs; this functionality has been removed. All credit goes to the original authors.
## Running
Double click on `MidiToMacro.ahk`.
To launch the program when Windows starts, you can add a shortcut to the file in your Start Menu\Startup folder.
The first time you launch the script, you will be prompted to choose a MIDI input device. If you need to change it later, you can right click on the system tray icon and click `MidiSet`. Or, you can open the `MidiMon`, and change the input in the "Midi Input" dropdown menu; the script will automatically reload.
To see a log of recent MIDI input messages and any output events, right click on the system tray icon and click `MidiMon`. You can close this window, and the script will keep running in the background.
## Adding rules
You can add rules to the file `MidiRules.ahk`.
There are four handler functions you can modify:
- `ProcessNote`: handles note on/off events
- `ProcessCC`: handles CC (Control Change, or Continuous Control) events
- `ProcessPC`: handles patch change events
- `ProcessPitchBend`: handle pitch bend events
Within each function, you can have a series of `if/else` blocks.
```
if (cc = 21) {
; ...
} else if (cc = 51) {
; ...
} else if (cc = 52 and value != 0) {
; ...
}
```
A rule to toggle the mute button when receiving CC 51 might look like this:
```
if (cc = 51) {
Send {Volume_Mute}
DisplayOutput("Volume", "Mute")
}
```
`Send {Volume_Mute}` simulates pressing the "mute" button on your keyboard. `DisplayOutput("Volume", "Mute")` logs a message to the MidiMon GUI.
A rule to press the play/pause button might look like this:
```
if (cc = 54 and value != 0) {
Send {Media_Play_Pause}
DisplayOutput("Media", "Play/Pause")
}
```
`value != 0` lets us detect button presses, and ignores button releases, on our MIDI controller. (Without this clause, we'd send the keyboard macro twice; once for the button press, and agin for the button release.)
Here's a rule to map a continuous control from a slider to the main Windows mixer volume:
```
if (cc = 21 or cc = 29) {
scaled_value := ConvertCCValueToScale(value, 0, 127)
vol := scaled_value * 100
SoundSet, vol
DisplayOutput("Volume", vol)
}
```
`ConvertCCValueToScale` is a utility function from `CommonFunctions.ahk`. It converts a value within a give range into a floating point number between 0 and 1.
Here's a rule to trigger a keyboard shortcut in a specific application; in this example, Sound Forge 9:
```
if (cc = 58 and value != 0) {
; Place a cue marker in Sound Forge 9
ControlSend, , {Alt down}m{Alt up}, ahk_class #32770
DisplayOutput("Sound Forge", "Place Cue Marker")
}
```
You can use AutoHotKey's "WindowSpy" script to identify windows, or controls within an application, for use with `ahk_class`.
You can find [a list of standard CC messages online](https://www.midi.org/specifications-old/item/table-3-control-change-messages-data-bytes-2). You could use any control number without a specified control function, including numbers between 20-31, 52-63, and 102-119. But, any control number should work fine.

View File

@ -1,2 +0,0 @@
max_cc_val = 112
;cc_mappings = [ { cc: 67, output: "AxisX", invert: false, max: 112 }]

View File

@ -1,460 +0,0 @@
; VJoy_Test.ahk
#include %A_ScriptDir%\VJoy_lib.ahk
VJoy_Init()
nButtons := VJoy_GetVJDButtonNumber(iInterface)
cbtn := 1
StatStr := (status = VJD_STAT_OWN) ? "OWN" : "FREE" ; only FREE state required.
AxisMax_X := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_X)
AxisMax_Y := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_Y)
AxisMax_Z := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_Z)
AxisMax_RX := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RX)
AxisMax_RY := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RY)
AxisMax_RZ := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_RZ)
AxisMax_SL0 := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_SL0)
AxisMax_SL1 := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_SL1)
AxisMax_WHL := VJoy_GetVJDAxisMax(iInterface, HID_USAGE_WHL)
; build gui
Gui, Add, Text, w80 , Status: %StatStr%
Gui, add, Button, x100 y5 Default gBtnReset, Re&set
Gui, add, Button, x150 y5 gBtnReload, &Reload
Gui, add, Button, x200 y5 gBtnjoycpl, Open &cpl
Gui, Add, Text, x10, %nButtons% Buttons supported
Gui, Add, Button, x140 y30 gBtnTestAllON, Test all On
Gui, Add, Button, x210 y30 gBtnTestAllOFF, Off
Loop, %nButtons%
{
bX := ((Mod((A_Index-1), 8)) * 30 ) + 10
bY := FLOOR((A_Index-1) / 8) * 24 + 70
Gui, add, Button, h5 x%bx% y%by% gBtn%A_Index%, %A_Index%
}
nexty := 180
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_X)) {
Gui, Add, Text, x10 w130 y%nexty%, Axis X: 0 / %AxisMax_X%
Gui, Add, Slider, x140 y%nexty% vAxisX gSliderXChanged
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_Y)) {
Gui, Add, Text, x10 w130 y%nexty%, Axis Y: 0 / %AxisMax_Y%
Gui, Add, Slider, x140 y%nexty% vAxisY gSliderYChanged
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_Z)) {
Gui, Add, Text, x10 w130 y%nexty%, Axis Z: 0 / %AxisMax_Z%
Gui, Add, Slider, x140 y%nexty% vAxisZ gSliderZChanged
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_RX)) {
Gui, Add, Text, x10 w130 y%nexty%, Axis RX: 0 / %AxisMax_RX%
Gui, Add, Slider, x140 y%nexty% vAxisRX gSliderRXChanged
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_RY)) {
Gui, Add, Text, x10 w130 y%nexty%, Axis RY: 0 / %AxisMax_RY%
Gui, Add, Slider, x140 y%nexty% vAxisRY gSliderRYChanged
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_RZ)) {
Gui, Add, Text, x10 w130 y%nexty%, Axis RZ: 0 / %AxisMax_RZ%
Gui, Add, Slider, x140 y%nexty% vAxisRZ gSliderRZChanged
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_SL0)) {
Gui, Add, Text, x10 w130 y%nexty%, Slider0: 0 / %AxisMax_SL0%
Gui, Add, Slider, x140 y%nexty% vAxisSL0 gSliderSL0Changed
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_SL1)) {
Gui, Add, Text, x10 w130 y%nexty%, Slider1: 0 / %AxisMax_SL1%
Gui, Add, Slider, x140 y%nexty% vAxisSL1 gSliderSL1Changed
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (VJoy_GetVJDAxisExist(iInterface, HID_USAGE_WHL)) {
Gui, Add, Text, x10 w130 y%nexty%, Wheel: 0 / %AxisMax_WHL%
Gui, Add, Slider, x140 y%nexty% vAxisWHL gSliderWHLChanged
nexty += 40
} else {
Gui, Add, Text, x0 y0
}
if (ContPovNumber) {
Gui, Add, Text, x10 y%nexty%,Number of Continuous POVs: %ContPovNumber%
nexty += 20
Gui, Add, Text, x10 y%nexty%, Continuous Pov test
Gui, Add, Slider, x140 y%nexty% vPovValSlider gSliderContPov
nexty+=40
Gui, Add, Edit, x10 w80 y%nexty% vPovValDirect gEditContPov, -1
Loop, %ContPovNumber%
{
_contpov_listing := % _contpov_listing . A_Index
if (A_Index < ContPovNumber) {
_contpov_listing := % _contpov_listing . "|"
}
}
Gui, Add, ListBox, x140 w40 y%nexty% vContPovChoice gContPovChoose, %_contpov_listing%
nexty += 30
}
if (DiscPovNumber) {
Gui, Add, Text, x10 y%nexty%,Number of Descrete POVs: %DiscPovNumber%
nexty += 20
tmpy := nexty
Gui, Add, Button, x160 y%tmpy% gBtnPovN, N
tmpy := nexty + 30
Gui, Add, Button, x155 y%tmpy% gBtnPovNeu, Neu
tmpy := nexty + 60
Gui, Add, Button, x160 y%tmpy% gBtnPovS, S
tmpy := nexty + 30
Gui, Add, Button, x120 y%tmpy% gBtnPovW, W
Gui, Add, Button, x200 y%tmpy% gBtnPovE, E
Loop, %DiscPovNumber%
{
_contpov_listing := % _contpov_listing . A_Index
if (A_Index < DiscPovNumber) {
_contpov_listing := % _contpov_listing . "|"
}
}
Gui, Add, ListBox, x10 w40 y%nexty% vDiscPovChoice gDiscPovChoose, %_contpov_listing%
nexty += 100
}
GetKeyState, _JoyStat, JoyInfo
Gui, Add, Text, x10 y%nexty%, JoyInfo: %_JoyStat%
Gui, Show
return
SliderXChanged:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_X * AxisX / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_X)
ControlSetText, Static3, Axis X %tmp_axis_val% / %AxisMax_X%
return
SliderYChanged:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_Y * AxisY / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_Y)
ControlSetText, Static4, Axis Y %tmp_axis_val% / %AxisMax_Y%
return
SliderZChanged:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_Z * AxisZ / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_Z)
ControlSetText, Static5, Axis Z %tmp_axis_val% / %AxisMax_Z%
return
SliderRXChanged:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_RX * AxisRX / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_RX)
ControlSetText, Static6, Axis RX %tmp_axis_val% / %AxisMax_RX%
return
SliderRYChanged:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_RY * AxisRY / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_RY)
ControlSetText, Static7, Axis RY %tmp_axis_val% / %AxisMax_RY%
return
SliderRZChanged:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_RZ * AxisRZ / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_RZ)
ControlSetText, Static8, Axis RZ %tmp_axis_val% / %AxisMax_RZ%
return
SliderSL0Changed:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_SL0 * AxisSL0 / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_SL0)
ControlSetText, Static9, Slider0 %tmp_axis_val% / %AxisMax_SL0%
return
SliderSL1Changed:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_SL1 * AxisSL1 / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_SL1)
ControlSetText, Static10, Slider1 %tmp_axis_val% / %AxisMax_SL1%
return
SliderWHLChanged:
Gui, Submit, NoHide
tmp_axis_val := Floor(AxisMax_WHL * AxisWHL / 100)
VJoy_SetAxis(tmp_axis_val, iInterface, HID_USAGE_WHL)
ControlSetText, Static11, Wheel %tmp_axis_val% / %AxisMax_WHL%
return
BtnReload:
F12::
VJoy_Close(iInterface)
Reload
return
;GuiClose:
; ExitApp
;return
OnExit:
VJoy_Close(iInterface)
return
; GUIBtn test all buttons
BtnTestAllON:
Loop, %nButtons%
{
VJoy_SetBtn(1, iInterface, A_Index)
}
return
BtnTestAllOFF:
Loop, %nButtons%
{
VJoy_SetBtn(0, iInterface, A_Index)
}
return
BtnTest(id, btn) {
VJoy_SetBtn(1, id, btn)
Sleep, 100
VJoy_SetBtn(0, id, btn) ; Release button 1
}
; GUIBtn1 for test button1
Btn1:
BtnTest(iInterface, 1)
return
Btn2:
BtnTest(iInterface, 2)
return
Btn3:
BtnTest(iInterface, 3)
return
Btn4:
BtnTest(iInterface, 4)
return
Btn5:
BtnTest(iInterface, 5)
return
Btn6:
BtnTest(iInterface, 6)
return
Btn7:
BtnTest(iInterface, 7)
return
Btn8:
BtnTest(iInterface, 8)
return
Btn9:
BtnTest(iInterface, 9)
return
Btn10:
BtnTest(iInterface, 10)
return
Btn11:
BtnTest(iInterface, 11)
return
Btn12:
BtnTest(iInterface, 12)
return
Btn13:
BtnTest(iInterface, 13)
return
Btn14:
BtnTest(iInterface, 14)
return
Btn15:
BtnTest(iInterface, 15)
return
Btn16:
BtnTest(iInterface, 16)
return
Btn17:
BtnTest(iInterface, 17)
return
Btn18:
BtnTest(iInterface, 18)
return
Btn19:
BtnTest(iInterface, 19)
return
Btn20:
BtnTest(iInterface, 20)
return
Btn21:
BtnTest(iInterface, 21)
return
Btn22:
BtnTest(iInterface, 22)
return
Btn23:
BtnTest(iInterface, 23)
return
Btn24:
BtnTest(iInterface, 24)
return
Btn25:
BtnTest(iInterface, 25)
return
Btn26:
BtnTest(iInterface, 26)
return
Btn27:
BtnTest(iInterface, 27)
return
Btn28:
BtnTest(iInterface, 28)
return
Btn29:
BtnTest(iInterface, 29)
return
Btn30:
BtnTest(iInterface, 30)
return
Btn31:
BtnTest(iInterface, 31)
return
Btn32:
BtnTest(iInterface, 32)
return
; Open Game Control Panel
Btnjoycpl:
RunWait %ComSpec% /C start joy.cpl,, Hide
return
BtnReset:
AxisX := AxisY := AxisZ := AxisRX := AxisRY := AxisRZ := Slider0 := Slider1 := 0
Gui, Submit, NoHide
VJoy_Close(iInterface)
VJoy_Init()
return
EditContPov:
Gui, Submit, NoHide
GuiControlGet, ContPovChoice
if (ContPovChoice < 1 or ContPovChoice > ContPovNumber) {
MsgBox, Please select a pov
return
}
if (PovValDirect < -1) {
PovValDirect := -1
Gui, Submit, NoHide
return
}
if (PovValDirect > 35999) {
PovValDirect := 35999
Gui, Submit, NoHide
return
}
VJoy_SetContPov(PovValDirect, iInterface, ContPovChoice)
return
SliderContPov:
Gui, Submit, NoHide
GuiControlGet, ContPovChoice
if (ContPovChoice < 1 or ContPovChoice > ContPovNumber) {
MsgBox, Please select a pov
return
}
PovValDirect := Floor(35999 * PovValSlider / 100)
ControlSetText, Edit1, %PovValDirect%
VJoy_SetContPov(PovValDirect, iInterface, ContPovChoice)
return
ContPovChoose:
Gui, Submit, NoHide
GuiControlGet, ContPovChoice
return
BtnPovNeu:
Gui, Submit, NoHide
GuiControlGet, DiscPovChoice
if (DiscPovChoice < 1 or DiscPovChoice > DiscPovNumber) {
MsgBox, Please select a pov
return
}
VJoy_SetDiscPov(-1, iInterface, DiscPovChoice)
return
BtnPovN:
Gui, Submit, NoHide
GuiControlGet, DiscPovChoice
if (DiscPovChoice < 1 or DiscPovChoice > DiscPovNumber) {
MsgBox, Please select a pov
return
}
VJoy_SetDiscPov(0, iInterface, DiscPovChoice)
return
BtnPovE:
Gui, Submit, NoHide
GuiControlGet, DiscPovChoice
if (DiscPovChoice < 1 or DiscPovChoice > DiscPovNumber) {
MsgBox, Please select a pov
return
}
VJoy_SetDiscPov(1, iInterface, DiscPovChoice)
return
BtnPovS:
Gui, Submit, NoHide
GuiControlGet, DiscPovChoice
if (DiscPovChoice < 1 or DiscPovChoice > DiscPovNumber) {
MsgBox, Please select a pov
return
}
VJoy_SetDiscPov(2, iInterface, DiscPovChoice)
return
BtnPovW:
Gui, Submit, NoHide
GuiControlGet, DiscPovChoice
if (DiscPovChoice < 1 or DiscPovChoice > DiscPovNumber) {
MsgBox, Please select a pov
return
}
VJoy_SetDiscPov(3, iInterface, DiscPovChoice)
return
DiscPovChoose:
Gui, Submit, NoHide
GuiControlGet, DiscPovChoice
return

View File

@ -1,175 +0,0 @@
;VJoy_lib.ahk
iInterface = 2 ; Default target vJoy device
; ported from VjdStat in vjoyinterface.h
VJD_STAT_OWN := 0 ; The vJoy Device is owned by this application.
VJD_STAT_FREE := 1 ; The vJoy Device is NOT owned by any application (including this one).
VJD_STAT_BUSY := 2 ; The vJoy Device is owned by another application. It cannot be acquired by this application.
VJD_STAT_MISS := 3 ; The vJoy Device is missing. It either does not exist or the driver is down.
VJD_STAT_UNKN := 4 ; Unknown
;HID Descriptor definitions(ported from public.h
HID_USAGE_X := 0x30
HID_USAGE_Y := 0x31
HID_USAGE_Z := 0x32
HID_USAGE_RX := 0x33
HID_USAGE_RY := 0x34
HID_USAGE_RZ := 0x35
HID_USAGE_SL0 := 0x36
HID_USAGE_SL1 := 0x37
HID_USAGE_WHL := 0x38
HID_USAGE_POV := 0x39
VJoy_init() {
Global iInterface, VJD_STAT_OWN, VJD_STAT_FREE, VJD_STAT_BUSY, VJD_STAT_MISS, VJD_STAT_UNKN, ContPovNumber, DiscPovNumber, hDLL
SetWorkingDir, %A_ScriptDir%
curdir:=A_WorkingDir
if (!hDLL) {
dllpath = %A_ScriptDir%\vJoyInterface.dll
hDLL := DLLCall("LoadLibrary", "Str", dllpath)
if (!hDLL) {
MsgBox, LoadLibrary %dllpath% fail
}
}
result := DllCall("vJoyInterface.dll\vJoyEnabled", "Int")
if (ErrorLevel = 4) {
MsgBox, Error! VJoy library "vJoyInterface.dll" is not found!`nErrorLevel:%ErrorLevel%
ExitApp
}
if (!result) {
MsgBox, Error! VJoy interface is not installed!`nErrorLevel:%ErrorLevel%
ExitApp
}
status := DllCall("vJoyInterface\GetVJDStatus", "Int", iInterface)
if (status = VJD_STAT_OWN) {
ToolTip, vJoy Device %iInterface% is already owned by this feeder
} else if (status = VJD_STAT_FREE) {
ToolTip, vJoy Device %iInterface% is free
} else if (status = VJD_STAT_BUSY) {
MsgBox vJoy Device %iInterface% is already owned by another feeder`nCannot continue`n
ExitApp
} else if (status = VJD_STAT_MISS) {
MsgBox vJoy Device %iInterface% is not installed or disabled`nCannot continue`n
ExitApp
} else {
MsgBox vJoy Device %iInterface% general error`nCannot continue`n
ExitApp
}
Sleep, 50
ToolTip
; Get the number of buttons and POV Hat switchessupported by this vJoy device
ContPovNumber := DllCall("vJoyInterface\GetVJDContPovNumber", "UInt", iInterface, "Int")
DiscPovNumber := DllCall("vJoyInterface\GetVJDDiscPovNumber", "UInt", iInterface, "Int")
; Acquire the target device
if (status = VJD_STAT_FREE) {
ac_jvd := VJoy_AcquireVJD(iInterface)
}
if ((status = VJD_STAT_OWN) || ((status = VJD_STAT_FREE) && (!ac_jvd))) {
MsgBox % "Failed to acquire vJoy device number % iInterface "
ExitApp
} else {
ToolTip, Acquired: vJoy device number %iInterface%
}
Sleep, 50
ToolTip
VJoy_ResetVJD(iInterface)
; VJoy_RelinquishVJD(iInterface)
return
}
VJoy_AcquireVJD(id) {
return DllCall("vJoyInterface\AcquireVJD", "UInt", id)
}
VJoy_GetVJDStatus(id) {
status := DllCall("vJoyInterface\GetVJDStatus", "UInt", id)
return status
}
VJoy_GetVJDButtonNumber(id) {
res := DllCall("vJoyInterface\GetVJDButtonNumber", "Int", id)
return res
}
VJoy_SetBtn(sw, id, btn_id) {
res := DllCall("vJoyInterface\SetBtn", "Int", sw, "UInt", id, "UChar", btn_id)
if (!res) {
MsgBox, SetBtn(%sw%, %id%, %btn_id%) err: %ErrorLevel%`nnLastError: %A_LastError%
}
return res
}
VJoy_ResetAll() {
res := DllCall("vJoyInterface\ResetAll")
return res
}
VJoy_ResetVJD(id) {
res := DllCall("vJoyInterface\ResetVJD", "UInt", id)
return res
}
VJoy_GetVJDAxisMax(id, usage) {
res := DllCall("vJoyInterface\GetVJDAxisMax", "Int", id, "Int", usage, "IntP", Max_Axis)
return Max_Axis
}
VJoy_GetVJDAxisExist(id, usage) {
Axis_t := DllCall("vJoyInterface\GetVJDAxisExist", "UInt", id, "UInt", usage)
if (!Axis_t) {
; MsgBox, GetVJDAxisExist Error!`nErrorLevel:%ErrorLevel%
}
if (ErrorLevel) {
ToolTip, GetVJDAxisExist Warning!`nErrorLevel:%ErrorLevel%
ToolTip
}
return Axis_t
}
VJoy_SetAxis(axis_val, id, usage) {
res := DllCall("vJoyInterface\SetAxis", "Int", axis_val, "UInt", id, "UInt", usage)
if (!res) {
MsgBox, SetAxis Error!`nErrorLevel:%ErrorLevel%
}
return res
}
VJoy_RelinquishVJD(id) {
DllCall("vJoyInterface\RelinquishVJD", "UInt", id)
}
VJoy_Close(id) {
VJoy_ResetAll()
VJoy_RelinquishVJD(id)
if (hDLL) {
DLLCall("FreeLibraly", "Ptr", hDLL)
hDLL:=
}
}
VJoy_SetDiscPov(Value, id, nPov) {
_res := DllCall("vJoyInterface\SetDiscPov", "Int", Value, "UInt", id, "UChar", nPov)
if (!_res) {
MsgBox, SetDiscPov err: %ErrorLevel%
}
return _ef_res
}
VJoy_SetContPov(Value, id, nPov) {
_res := DllCall("vJoyInterface\SetContPov", "Int", Value, "UInt", id, "UChar", nPov)
if (!_res) {
MsgBox, SetContPov err: %ErrorLevel%
}
return _ef_res
}

View File

@ -1,839 +0,0 @@
; VJoy_lib.ahk Ver1.1
; Original code by Axlar - http://www.autohotkey.com/board/topic/87690-
; modded by evilC - VJoy_SetAxis fix (Bad ternary operator)
VJD_MAXDEV := 16
; ported from VjdStat in vjoyinterface.h
VJD_STAT_OWN := 0 ; The vJoy Device is owned by this application.
VJD_STAT_FREE := 1 ; The vJoy Device is NOT owned by any application (including this one).
VJD_STAT_BUSY := 2 ; The vJoy Device is owned by another application. It cannot be acquired by this application.
VJD_STAT_MISS := 3 ; The vJoy Device is missing. It either does not exist or the driver is down.
VJD_STAT_UNKN := 4 ; Unknown
; HID Descriptor definitions(ported from public.h
HID_USAGE_X := 0x30
HID_USAGE_Y := 0x31
HID_USAGE_Z := 0x32
HID_USAGE_RX:= 0x33
HID_USAGE_RY:= 0x34
HID_USAGE_RZ:= 0x35
HID_USAGE_SL0:= 0x36
HID_USAGE_SL1:= 0x37
VJDev := Object()
; Load lib from already load or current/system directory
VJoy_LoadLibrary() {
Global hVJDLL
if (hVJDLL) {
return hVJDLL
}
; Load dll from any path or get handle of already loaded
hVJDLL := DLLCall("LoadLibrary", "Str", "vJoyInterface")
if (hVJDLL) {
return hVJDLL
}
; If dll deployed into current and it was wrong, warn
dllpath = %A_ScriptDir%\vJoyInterface.dll
if (FileExist(dllpath)) {
if (A_Is64bitOS) {
is64bit = 64-bitOS
}
AHKEd := (A_PtrSize = 4) ? "32-bit" : "64-bit"
RequiredDLL := (A_PtrSize = 4) ? "x86" : "x64"
dll_info := GetFileVersion(dllpath)
if (dll_info and !InStr(dll_info, RequiredDLL)) {
isWrong = =wrong!
}
MsgBox,
(
LoadLibrary %dllpath% failed!
Exiting.
Make sure %RequiredDLL% vJoyInterface.dll is in %A_ScriptDir%
(%dll_info%%isWrong%)
AutoHotkey: %AHKEd%
OSVersion:%A_OSVersion% %is64bit%
)
}
return 0
}
GetFileVersion(pszFilePath) {
dwSize := DLLCall("Version\GetFileVersionInfoSize", "Str", pszFilePath)
if (!dwSize) {
return
}
VarSetCapacity(pvData, dwSize)
if (!DLLCall("Version\GetFileVersionInfo", "Str", pszFilePath
, "Int", 0, "Int", dwSize, "Ptr", &pvData)) {
return
}
; Get British product version string
if (!DLLCall("Version\VerQueryValue", "UInt", &pvData, "Str"
, "\\StringFileInfo\\040904b0\\ProductVersion", "UIntP"
, lpTranslate, "UInt", 0)) {
return
}
return StrGet(lpTranslate)
}
Class VJoyDev {
__New(dev_id) {
Global NoticeDone, hVJDLL, VJD_STAT_OWN, VJD_STAT_FREE, VJD_STAT_BUSY, VJD_STAT_MISS, VJD_STAT_UNKN,HID_USAGE_X,HID_USAGE_Y,HID_USAGE_Z,HID_USAGE_RX,HID_USAGE_RY,HID_USAGE_RZ,HID_USAGE_SL0,HID_USAGE_SL1
if (!hVJDLL) {
hVJDLL := VJoy_LoadLibrary()
}
if (!hVJDLL) {
if (!NoticeDone) {
NoticeDone := True
MsgBox, [VJoy Constructer] LoadLibrary vJoyInterface.dll failed!
}
return
}
this.DeviceEnabled := DllCall("vJoyInterface.dll\vJoyEnabled")
if (ErrorLevel = 4) {
MsgBox, Error! VJoy library "vJoyInterface.dll" is not found!`nErrorLevel:%ErrorLevel%
return
}
if (!this.DeviceEnabled) {
;MsgBox, Error! VJoy interface is not installed!`nErrorLevel:%ErrorLevel%
return
}
DeviceStatus := DllCall("vJoyInterface\GetVJDStatus", "UInt", dev_id)
if (DeviceStatus = VJD_STAT_OWN) {
stat_str = VJD_STAT_OWN
;ToolTip, vJoy Device %dev_id% is already owned by this feeder
} else if (DeviceStatus = VJD_STAT_FREE) {
;ToolTip, vJoy Device %dev_id% is free
stat_str = VJD_STAT_FREE
} else if (DeviceStatus = VJD_STAT_BUSY) {
MsgBox vJoy Device %dev_id% is already owned by another feeder`nCannot continue`n
stat_str = VJD_STAT_BUSY
return
} else if (DeviceStatus = VJD_STAT_MISS) {
;MsgBox vJoy Device %dev_id% is not installed or disabled`nCannot continue`n
stat_str = VJD_STAT_MISS
return
} else {
stat_str = VJD_STAT_UNKN
MsgBox vJoy Device %dev_id% general error`nCannot continue`n
return
}
;ToolTip
; Get the number of buttons and POV Hat switchessupported by this vJoy device
this.ContPovNumber := DllCall("vJoyInterface\GetVJDContPovNumber", "UInt", dev_id)
this.ContPov := Object()
Loop, % this.ContPovNumber ; insert dummy
this.ContPov.Insert(A_Index, 0)
this.DiscPovNumber := DllCall("vJoyInterface\GetVJDDiscPovNumber", "UInt", dev_id)
this.DiscPov := Object()
Loop, % this.DiscPovNumber ; insert dummy
this.DiscPov.Insert(A_Index, 0)
this.NumberOfButtons := DllCall("vJoyInterface\GetVJDButtonNumber", "Int", dev_id)
this.Btn := Object()
Loop, % this.NumberOfButtons ; insert dummy
this.Btn.Insert(A_Index, 0)
this.AxisExist_X := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_X )
this.AxisExist_Y := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_Y )
this.AxisExist_Z := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_Z )
this.AxisExist_RX := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_RX )
this.AxisExist_RY := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_RY )
this.AxisExist_RZ := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_RZ )
this.AxisExist_SL0 := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_SL0)
this.AxisExist_SL1 := DllCall("vJoyInterface\GetVJDAxisExist", "Int", dev_id, "Int", HID_USAGE_SL1)
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_X, "IntP", nResult)) {
this.AxisMax_X := nResult
}
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_Y, "IntP", nResult)) {
this.AxisMax_Y := nResult
}
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_Z, "IntP", nResult)) {
this.AxisMax_Z := nResult
}
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_RX, "IntP", nResult)) {
this.AxisMax_RX := nResult
}
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_RY, "IntP", nResult)) {
this.AxisMax_RY := nResult
}
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_RZ, "IntP", nResult)) {
this.AxisMax_RZ := nResult
}
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_SL0, "IntP", nResult)) {
this.Slider0_Max := nResult
}
if (DllCall("vJoyInterface\GetVJDAxisMax", "Int", dev_id, "Int", HID_USAGE_SL1, "IntP", nResult)) {
this.Slider1_Max := nResult
}
; Acquire the target device
if (DeviceStatus = VJD_STAT_FREE) {
ac_jvd := DllCall("vJoyInterface\AcquireVJD", "UInt", dev_id)
if (!ac_jvd) {
MsgBox, Dev:%dev_id% aquire fail ErrorLevel: %ErrorLevel%
}
}
if (DeviceStatus = VJD_STAT_OWN) {
MsgBox % "Failed to acquire vJoy device number: " dev_id "`n(Other process owned device)"
return
} else if (DeviceStatus = VJD_STAT_FREE and !ac_jvd ) {
MsgBox % "Failed to acquire vJoy device number: " dev_id "`nAcquired: " ac_jvd
return
} else {
;ToolTip, % "Acquired: vJoy device number: " dev_id
}
;ToolTip
this.DeviceID := dev_id
this.DeviceStatus := DeviceStatus
this.Reset()
this.DeviceReady := True
return this
}
__Delete() {
this.Relinquish()
}
SetAxis(axis_val, usage) {
res := DllCall("vJoyInterface\SetAxis", "Int", axis_val, "UInt", this.DeviceID, "UInt", usage)
if (!res) {
MsgBox, SetAxis(%axis_val%`,%usage%) Error!`nErrorLevel:%ErrorLevel%
}
return res
}
SetAxis_X(axis_val) {
Global HID_USAGE_X
new_val := parse_rel_val(axis_val, this.Axis_X, this.AxisMax_X)
res := this.SetAxis(new_val, HID_USAGE_X)
if (res) {
this.Axis_X := new_val
}
return res
}
SetAxis_Y(axis_val) {
Global HID_USAGE_Y
new_val := parse_rel_val(axis_val, this.Axis_Y, this.AxisMax_Y)
res := this.SetAxis(new_val, HID_USAGE_Y)
if (res) {
this.Axis_Y := new_val
}
return res
}
SetAxis_Z(axis_val) {
Global HID_USAGE_Z
new_val := parse_rel_val(axis_val, this.Axis_Z, this.AxisMax_Z)
res := this.SetAxis(new_val, HID_USAGE_Z)
if (res) {
this.Axis_Z := new_val
}
return res
}
SetAxis_RX(axis_val) {
Global HID_USAGE_RX
new_val := parse_rel_val(axis_val, this.Axis_RX, this.AxisMax_RX)
res := this.SetAxis(new_val, HID_USAGE_RX)
if (res) {
this.Axis_RX := new_val
}
return res
}
SetAxis_RY(axis_val) {
Global HID_USAGE_RY
new_val := parse_rel_val(axis_val, this.Axis_RY, this.AxisMax_RY)
res := this.SetAxis(new_val, HID_USAGE_RY)
if (res) {
this.Axis_RY := new_val
}
return res
}
SetAxis_RZ(axis_val) {
Global HID_USAGE_RZ
new_val := parse_rel_val(axis_val, this.Axis_RZ, this.AxisMax_RZ)
res := this.SetAxis(new_val, HID_USAGE_RZ)
if (res) {
this.Axis_RZ := new_val
}
return res
}
SetAxis_SL0(axis_val) {
Global HID_USAGE_SL0
new_val := parse_rel_val(axis_val, this.Axis_SL0, this.AxisMax_SL0)
res := this.SetAxis(new_val, HID_USAGE_SL0)
if (res) {
this.Slider0 := new_val
}
return res
}
SetAxis_SL1(axis_val) {
Global HID_USAGE_SL1
new_val := parse_rel_val(axis_val, this.Axis_SL1, this.AxisMax_SL1)
res := this.SetAxis(new_val, HID_USAGE_SL1)
if (res) {
this.Slider1 := new_val
}
return res
}
GetBtn(bid) {
if (bid < 1 or bid > this.NumberOfButtons) {
return 0
}
return this.Btn[bid]
}
SetBtn(sw, btn_id) {
if (btn_id < 1 or btn_id > this.NumberOfButtons) {
MsgBox, SetBtn: range check error!
return 0
}
res := DllCall("vJoyInterface\SetBtn", "Int", sw, "UInt", this.DeviceID, "UChar", btn_id)
if (res) {
this.Btn[btn_id] := sw
}
return res
}
SetDiscPov(Value, nPov) {
_res := DllCall("vJoyInterface\SetDiscPov", "Int", Value, "UInt", this.DeviceID, "UChar", nPov)
if (!_res) {
MsgBox, SetDiscPov err: %ErrorLevel%
} else {
this.DiscPov[nPov] := Value
}
return _res
}
SetContPov(Value, nPov) {
_res := DllCall("vJoyInterface\SetContPov", "Int", Value, "UInt", this.DeviceID, "UChar", nPov)
if (!_res) {
MsgBox, SetContPov err: %ErrorLevel%
} else {
this.ContPov[nPov] := Value
}
return _res
}
Reset() {
; Reset local state values
this.Axis_X := 0
this.Axis_Y := 0
this.Axis_Z := 0
this.Axis_RX := 0
this.Axis_RY := 0
this.Axis_RZ := 0
this.Slider0 := 0
this.Slider1 := 0
for i in this.ContPov
this.ContPov[i] := 0
for i in this.DiscPov
this.DiscPov[i] := 0
for i in this.Btn
this.Btn[i] := 0
return DllCall("vJoyInterface\ResetVJD", "UInt", this.DeviceID)
}
Relinquish() {
return DllCall("vJoyInterface\RelinquishVJD", "UInt", this.DeviceID)
}
}
VJoy_init(id := 1) {
Global VJDev, VJD_MAXDEV
if (id < 1 || id > VJD_MAXDEV) {
MsgBox, [%A_ThisFunc%] Device %id% is invalid. Please specify 1-%VJD_MAXDEV%.
return
}
VJDev[id] := new VJoyDev(id)
return VJDev[id]
}
VJoy_DeviceErr(id) {
Global VJD_MAXDEV, VJDev
if (id < 1 or id > VJD_MAXDEV) {
MsgBox, [%A_ThisFunc%] Device %id% is invalid. Please specify 1-%VJD_MAXDEV%.
return True
}
if (!VJDev[id].DeviceReady) {
MsgBox, [%A_ThisFunc%] Device %id% is not ready.
return True
}
return False
}
VJoy_Ready(id) {
Global VJD_MAXDEV, VJDev
if (id < 1 || id > VJD_MAXDEV) {
return False
}
return VJDev[id].DeviceReady
}
VJoy_ResetVJD(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Reset()
}
VJoy_ResetAll() {
return DllCall("vJoyInterface\ResetAll")
}
; Release device
VJoy_RelinquishVJD(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Relinquish()
}
; Acquire device - added by evilC
VJoy_AcquireVJD(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return DllCall("vJoyInterface\AcquireVJD", "UInt", id)
}
; destructor
VJoy_Close() {
Global VJDev
VJoy_ResetAll()
for idx, dev in VJDev
dev.delete
if (hVJDLL) {
DLLCall("FreeLibraly", "Ptr", hVJDLL)
hVJDLL:=
}
}
VJoy_GetContPovNumber(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].ContPovNumber
}
VJoy_GetDiscPovNumber(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].DiscPovNumber
}
VJoy_GetVJDButtonNumber(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].NumberOfButtons
}
VJoy_GetAxisExist_X(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_X
}
VJoy_GetAxisExist_Y(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_Y
}
VJoy_GetAxisExist_Z(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_Z
}
VJoy_GetAxisExist_RX(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_RX
}
VJoy_GetAxisExist_RY(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_RY
}
VJoy_GetAxisExist_RZ(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_RZ
}
VJoy_GetAxisExist_SL0(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_SL0
}
VJoy_GetAxisExist_SL1(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisExist_SL1
}
VJoy_GetAxisMax_X(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisMax_X
}
VJoy_GetAxisMax_Y(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisMax_Y
}
VJoy_GetAxisMax_Z(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisMax_Z
}
VJoy_GetAxisMax_RX(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisMax_RX
}
VJoy_GetAxisMax_RY(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisMax_RY
}
VJoy_GetAxisMax_RZ(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].AxisMax_RZ
}
VJoy_GetAxisMax_SL0(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Slider0_Max
}
VJoy_GetAxisMax_SL1(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Slider1_Max
}
; for compatibility
VJoy_GetVJDAxisMax(id, usage) {
Global VJDev, HID_USAGE_X,HID_USAGE_Y,HID_USAGE_Z,HID_USAGE_RX,HID_USAGE_RY,HID_USAGE_RZ,HID_USAGE_SL0,HID_USAGE_SL1
if (VJoy_DeviceErr(id))
return False
return (usage = HID_USAGE_X) ? VJDev[id].AxisMax_X :
(usage = HID_USAGE_Y) ? VJDev[id].AxisMax_Y :
(usage = HID_USAGE_Z) ? VJDev[id].AxisMax_Z :
(usage = HID_USAGE_RX) ? VJDev[id].AxisMax_RX :
(usage = HID_USAGE_RY) ? VJDev[id].AxisMax_RY :
(usage = HID_USAGE_RZ) ? VJDev[id].AxisMax_RZ :
(usage = HID_USAGE_SL0) ? VJDev[id].AxisMax_Y :
VJDev[id].AxisMax_SL1
}
VJoy_GetVJDAxisExist(id, usage) {
Global VJDev, HID_USAGE_X,HID_USAGE_Y,HID_USAGE_Z,HID_USAGE_RX,HID_USAGE_RY,HID_USAGE_RZ,HID_USAGE_SL0,HID_USAGE_SL1
if (VJoy_DeviceErr(id))
return False
return (usage = HID_USAGE_X) ? VJDev[id].AxisExist_X :
(usage = HID_USAGE_Y) ? VJDev[id].AxisExist_Y :
(usage = HID_USAGE_Z) ? VJDev[id].AxisExist_Z :
(usage = HID_USAGE_RX) ? VJDev[id].AxisExist_RX :
(usage = HID_USAGE_RY) ? VJDev[id].AxisExist_RY :
(usage = HID_USAGE_RZ) ? VJDev[id].AxisExist_RZ :
(usage = HID_USAGE_SL0) ? VJDev[id].AxisExist_Y :
VJDev[id].AxisExist_SL1
}
VJoy_GetBtn(id, btn_id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].GetBtn(btn_id)
}
VJoy_SetBtn(sw, id, btn_id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
res := VJDev[id].SetBtn(sw, btn_id)
if (!res) {
MsgBox, SetBtn(%sw%, %id%, %btn_id%) err: %ErrorLevel%`nnLastError: %A_LastError%
}
return res
}
VJoy_GetAxis_X(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Axis_X
}
VJoy_GetAxis_Y(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Axis_Y
}
VJoy_GetAxis_Z(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Axis_Z
}
VJoy_GetAxis_RX(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Axis_RX
}
VJoy_GetAxis_RY(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Axis_RY
}
VJoy_GetAxis_RZ(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Axis_RZ
}
VJoy_GetAxis_SL0(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Slider0
}
VJoy_GetAxis_SL1(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].Slider1
}
VJoy_SetAxis_X(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_X(axis_val)
}
VJoy_SetAxis_Y(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_Y(axis_val)
}
VJoy_SetAxis_Z(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_Z(axis_val)
}
VJoy_SetAxis_RX(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_RX(axis_val)
}
VJoy_SetAxis_RY(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_RY(axis_val)
}
VJoy_SetAxis_RZ(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_RZ(axis_val)
}
VJoy_SetAxis_SL0(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_SL0(axis_val)
}
VJoy_SetAxis_SL1(axis_val, id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetAxis_SL1(axis_val)
}
; for compatibility
VJoy_SetAxis(axis_val, id, usage) {
Global VJDev, HID_USAGE_X,HID_USAGE_Y,HID_USAGE_Z,HID_USAGE_RX,HID_USAGE_RY,HID_USAGE_RZ,HID_USAGE_SL0,HID_USAGE_SL1
if (VJoy_DeviceErr(id))
return False
if (usage == HID_USAGE_X){
return VJDev[id].SetAxis_X(axis_val)
} else if (usage == HID_USAGE_Y){
return VJDev[id].SetAxis_Y(axis_val)
} else if (usage == HID_USAGE_Z){
return VJDev[id].SetAxis_Z(axis_val)
} else if (usage == HID_USAGE_RX){
return VJDev[id].SetAxis_RX(axis_val)
} else if (usage == HID_USAGE_RY){
return VJDev[id].SetAxis_RY(axis_val)
} else if (usage == HID_USAGE_RZ){
return VJDev[id].SetAxis_RZ(axis_val)
} else if (usage == HID_USAGE_SL0){
return VJDev[id].SetAxis_SL0(axis_val)
} else if (usage == HID_USAGE_SL1){
return VJDev[id].SetAxis_SL1(axis_val)
} else {
MsgBox, Unknown Axis: %usage%
}
}
VJoy_GetDiscPov(id, nPov) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].DiscPov[nPov]
}
VJoy_SetDiscPov(Value, id, nPov) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetDiscPov(Value, nPov)
}
VJoy_GetContPov(id, nPov) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].ContPov[nPov]
}
VJoy_SetContPov(Value, id, nPov) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
return VJDev[id].SetContPov(Value, nPov)
}
; for debug: dump value of structure
VJoy_Dump(id) {
Global VJDev
if (VJoy_DeviceErr(id))
return False
num := VJoy_GetVJDButtonNumber(id)
for idx, btn in VJDev[id].Btn
{
if (idx<10)
buf1 .= "_"
buf1 .= idx . "|"
buf2 .= "_" . btn . "|"
}
str_btn = Button(%num%):`n %buf1%`n %buf2%`n
if (VJoy_GetAxisMax_X(id)) {
str_btn .= "Axis_X: " . VJoy_GetAxis_X(id) . "`n"
}
if (VJoy_GetAxisMax_Y(id)) {
str_btn .= "Axis_Y: " . VJoy_GetAxis_Y(id) . "`n"
}
if (VJoy_GetAxisMax_Z(id)) {
str_btn .= "Axis_Z: " . VJoy_GetAxis_Z(id) . "`n"
}
if (VJoy_GetAxisMax_RX(id)) {
str_btn .= "Axis_RX: " . VJoy_GetAxis_RX(id) . "`n"
}
if (VJoy_GetAxisMax_RY(id)) {
str_btn .= "Axis_RY: " . VJoy_GetAxis_RY(id) . "`n"
}
if (VJoy_GetAxisMax_RZ(id)) {
str_btn .= "Axis_RZ: " . VJoy_GetAxis_RZ(id) . "`n"
}
if (VJoy_GetAxisMax_SL0(id)) {
str_btn .= "Axis_SL0: " . VJoy_GetAxis_SL0(id) . "`n"
}
if (VJoy_GetAxisMax_SL1(id)) {
str_btn .= "Axis_SL1: " . VJoy_GetAxis_SL1(id) . "`n"
}
num := VJoy_GetContPovNumber(id)
if (num) {
for idx, btn in VJDev[id].ContPov
{
Loop, % (StrLen(btn) - 1)
buf3 .= "_"
buf3 .= idx . "|"
buf4 .= btn . "|"
}
str_cont = ContPov(%num%):`n %buf3%`n %buf4%`n
} else {
str_cont = No Continuous Button.`n
}
str_btn .= str_cont
num := VJoy_GetDiscPovNumber(id)
if (num) {
for idx, btn in VJDev[id].DiscPov
{
Loop, % (StrLen(btn) - 1)
buf5 .= "_"
buf5 .= idx . "|"
buf6 .= btn . "|"
}
str_Disc = DiscPov(%num%):`n %buf5%`n %buf6%`n
} else {
str_Disc = No Discrete Button.`n
}
str_btn .= str_Disc
ToolTip, %str_btn%
}
parse_rel_val(invar, curval, max) {
if (InStr(invar, "+")) {
StringReplace, _buffer, invar, +
res := curval + _buffer
if (res > max)
return max
return res
} else if (InStr(invar, "-")) {
StringReplace, _buffer, invar, -
res := curval - _buffer
if (res < 0)
return 0
return res
}
return invar
}

View File

@ -1,84 +0,0 @@
; none of this is written by genmce - just lifted from ahk forum
; I think Chris wrote it - good for joystick info.
; July 6, 2005: Added auto-detection of joystick number.
; May 8, 2005 : Fixed: JoyAxes is no longer queried as a means of
; detecting whether the joystick is connected. Some joysticks are
; gamepads and don't have even a single axis.
; If you want to unconditionally use a specific joystick number, change
; the following value from 0 to the number of the joystick (1-16).
; A value of 0 causes the joystick number to be auto-detected:
JoystickNumber = 2
; END OF CONFIG SECTION. Do not make changes below this point unless
; you wish to alter the basic functionality of the script.
; Auto-detect the joystick number if called for:
if JoystickNumber <= 0
{
Loop 16 ; Query each joystick number to find out which ones exist.
{
GetKeyState, JoyName, %A_Index%JoyName
if JoyName <>
{
JoystickNumber = %A_Index%
break
}
}
if JoystickNumber <= 0
{
MsgBox The system does not appear to have any joysticks.
ExitApp
}
}
#SingleInstance
SetFormat, float, 03 ; Omit decimal point from axis position percentages.
GetKeyState, joy_buttons, %JoystickNumber%JoyButtons
GetKeyState, joy_name, %JoystickNumber%JoyName
GetKeyState, joy_info, %JoystickNumber%JoyInfo
Loop
{
buttons_down =
Loop, %joy_buttons%
{
GetKeyState, joy%a_index%, %JoystickNumber%joy%a_index%
if joy%a_index% = D
buttons_down = %buttons_down%%a_space%%a_index%
}
GetKeyState, joyx, %JoystickNumber%JoyX
axis_info = X%joyx%
GetKeyState, joyy, %JoystickNumber%JoyY
axis_info = %axis_info%%a_space%%a_space%Y%joyy%
IfInString, joy_info, Z
{
GetKeyState, joyz, %JoystickNumber%JoyZ
axis_info = %axis_info%%a_space%%a_space%Z%joyz%
}
IfInString, joy_info, R
{
GetKeyState, joyr, %JoystickNumber%JoyR
axis_info = %axis_info%%a_space%%a_space%R%joyr%
}
IfInString, joy_info, U
{
GetKeyState, joyu, %JoystickNumber%JoyU
axis_info = %axis_info%%a_space%%a_space%U%joyu%
}
IfInString, joy_info, V
{
GetKeyState, joyv, %JoystickNumber%JoyV
axis_info = %axis_info%%a_space%%a_space%V%joyv%
}
IfInString, joy_info, P
{
GetKeyState, joyp, %JoystickNumber%JoyPOV
axis_info = %axis_info%%a_space%%a_space%POV%joyp%
}
ToolTip, %joy_name% (#%JoystickNumber%):`n%axis_info%`nButtons Down: %buttons_down%`n`n(right-click the tray icon to exit)
Sleep, 100
}
return
esc::ExitApp

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.