Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Want to help the VideoLAN project? Designers, testers, translators, please come...
This is NOT about GETTING some help.
Forum rules
Please read the forum's rules carefully before posting. This forum should not be used to post VLC usage related questions.
SumDood
New Cone
New Cone
Posts: 7
Joined: 21 Feb 2014 08:20

Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby SumDood » 21 Feb 2014 08:47

Quite a few people online have expressed an interest in being able to control VLC using a foot pedal. I wanted to let the community know about a solution.

I am successfully using the Infinity USB foot pedal (IN-USB2) to control VLC in the background, for transcription purposes. I type in a word processor, and am able to control VLC playing in the background, using my foot pedal. This solution requires the AutoHotkey scripting engine, and one of the following scripts:

32 bit:

Code: Select all

; This script allows you to use a USB foot pedal to control VLC in the ; background, in this case, for transcription. This script has been ; tested with a VEC Infinity IN-USB-2 3-function foot pedal. This ; particular foot pedal has 3 buttons, and, therefore, 6 programmable ; functions, as each button can be pressed or released. ; ; To use this script, save it as FootPedal32.ahk and launch it with ; AutoHotkey installed. ; ; See below for more information on customizing this script for VLC. ; ; This version of the script is for the 32-bit version of AutoHotkey. ; ; This script was taken from http://tinyurl.com/k5gylb2 combined with ; http://tinyurl.com/k5jc24e ; ; Thanks go out to all who contributed to this script, and the makers ; of AutoHotkey. ; OnMessage(0x00FF, "InputMessage") RegisterHIDDevice(12, 3) ; Register Foot Pedal PedalLastPress := 0 Return ProcessPedalInput(input) { global PedalLastPress ; The input are combinations of 1, 2, 4 with 00 appended to the end ; indicating which pedals are pressed. ; For example, pressing the leftmost pedal triggers input 100, middle pedal 200, etc. ; all three pedals presses together will trigger 700 (1 ^ 2 ^ 4 = 7) ; Release of pedal trigger an input indicating what pedals are still held down input := input//100 If (input > PedalLastPress) PressKey((PedalLastPress & input) ^ input) ; Else ; ReleaseKey((PedalLastPress & input) ^ PedalLastPress) PedalLastPress := input } ; The ControlSend command allows simulated keystrokes to be sent to any running ; program, even if it is running in the background. For more information on how ; it works, see http://www.autohotkey.com/docs/commands/ControlSend.htm ; For more information on which commands can be sent, and how to format them, ; see http://www.autohotkey.com/docs/commands/Send.htm PressKey(bits) { SetTitleMatchMode, 2 If (bits & 1) ; left pedal { ;Msgbox Left pedal pressed! ControlSend,,{=}+{Left},VLC media player ;Normalizes playback speed, and rewinds 3 seconds } Else If (bits & 4) ; right pedal { ;Msgbox Right pedal pressed! ControlSend,,{]},VLC media player ;Increases playback speed by 0.1x increments } Else ; center pedal { ;MsgBox Center pedal pressed! ControlSend,,{Space},VLC media player ;Play/pause } } ; The following function should be uncommented & customized to your liking ; if you would like to utilize different actions upon releasing the foot ; pedal buttons ;ReleaseKey(bits) ;{ ; ToolTip Releasing %bits% ; SetTitleMatchMode, 2 ; If (bits & 1) ; MsgBox left pedal up! ; Else If (bits & 4) ; MsgBox Right pedal up! ; Else ; MsgBox Center pedal up! ;} Mem2Hex( pointer, len ) { A_FI := A_FormatInteger SetFormat, Integer, Hex Loop, %len% { Hex := *Pointer+0 StringReplace, Hex, Hex, 0x, 0x0 StringRight Hex, Hex, 2 hexDump := hexDump . hex Pointer ++ } SetFormat, Integer, %A_FI% StringUpper, hexDump, hexDump Return hexDump } ; Keyboards are always Usage 6, Usage Page 1, Mice are Usage 2, Usage Page 1, ; HID devices specify their top level collection in the info block RegisterHIDDevice(UsagePage,Usage) { ; local RawDevice,HWND RIDEV_INPUTSINK := 0x00000100 DetectHiddenWindows, on HWND := WinExist("ahk_class AutoHotkey ahk_pid " DllCall("GetCurrentProcessId")) DetectHiddenWindows, off VarSetCapacity(RawDevice, 12) NumPut(UsagePage, RawDevice, 0, "UShort") NumPut(Usage, RawDevice, 2, "UShort") NumPut(RIDEV_INPUTSINK, RawDevice, 4) NumPut(HWND, RawDevice, 8) Res := DllCall("RegisterRawInputDevices", "UInt", &RawDevice, UInt, 1, UInt, 12) if (Res = 0) MsgBox, Failed to register for HID Device } InputMessage(wParam, lParam, msg, hwnd) { RID_INPUT := 0x10000003 RIM_TYPEHID := 2 SizeofRidDeviceInfo := 32 RIDI_DEVICEINFO := 0x2000000b DllCall("GetRawInputData", UInt, lParam, UInt, RID_INPUT, UInt, 0, "UInt *", Size, UInt, 16) VarSetCapacity(Buffer, Size) DllCall("GetRawInputData", UInt, lParam, UInt, RID_INPUT, UInt, &Buffer, "UInt *", Size, UInt, 16) Type := NumGet(Buffer, 0 * 4) Size := NumGet(Buffer, 1 * 4) Handle := NumGet(Buffer, 2 * 4) VarSetCapacity(Info, SizeofRidDeviceInfo) NumPut(SizeofRidDeviceInfo, Info, 0) Length := SizeofRidDeviceInfo DllCall("GetRawInputDeviceInfo", UInt, Handle, UInt, RIDI_DEVICEINFO, UInt, &Info, "UInt *", SizeofRidDeviceInfo) VenderID := NumGet(Info, 4 * 2) Product := NumGet(Info, 4 * 3) ; tooltip %VenderID% %Product% if (Type = RIM_TYPEHID) { SizeHid := NumGet(Buffer, (16 + 0)) InputCount := NumGet(Buffer, (16 + 4)) Loop %InputCount% { Addr := &Buffer + 24 + ((A_Index - 1) * SizeHid) BAddr := &Buffer Input := Mem2Hex(Addr, SizeHid) If (VenderID = 1523 && Product = 255) ; need special function to process foot pedal input ProcessPedalInput(Input) Else If (IsLabel(Input)) { Gosub, %Input% } } } }
64 bit:

Code: Select all

; This script allows you to use a USB foot pedal to control VLC in the ; background, in this case, for transcription. This script has been ; tested with a VEC Infinity IN-USB-2 3-function foot pedal. This ; particular foot pedal has 3 buttons, and, therefore, 6 programmable ; functions, as each button can be pressed or released. ; ; To use this script, save it as FootPedal64.ahk and launch it with ; AutoHotkey installed. ; ; See below for more information on customizing this script for VLC. ; ; This version of the script is for the 64-bit version of AutoHotkey. ; ; This script was taken from http://tinyurl.com/k5gylb2 combined with ; http://tinyurl.com/k5jc24e ; ; Thanks go out to all who contributed to this script, and the makers ; of AutoHotkey. ; OnMessage(0x00FF, "InputMessage") RegisterHIDDevice(12, 3) ; Register Foot Pedal PedalLastPress := 0 Return ProcessPedalInput(input) { global PedalLastPress ; The input are combinations of 1, 2, 4 with 00 appended to the end ; indicating which pedals are pressed. ; For example, pressing the leftmost pedal triggers input 100, middle pedal 200, etc. ; all three pedals presses together will trigger 700 (1 ^ 2 ^ 4 = 7) ; Release of pedal trigger an input indicating what pedals are still held down input := input//100 If (input > PedalLastPress) PressKey((PedalLastPress & input) ^ input) ; Else ; ReleaseKey((PedalLastPress & input) ^ PedalLastPress) PedalLastPress := input } ; The ControlSend command allows simulated keystrokes to be sent to any running ; program, even if it is running in the background. For more information on how ; it works, see http://www.autohotkey.com/docs/commands/ControlSend.htm ; For more information on which commands can be sent, and how to format them, ; see http://www.autohotkey.com/docs/commands/Send.htm PressKey(bits) { SetTitleMatchMode, 2 If (bits & 1) ; left pedal { ;Msgbox Left pedal pressed! ControlSend,,{=}+{Left},VLC media player ;Normalizes playback speed, and rewinds 3 seconds } Else If (bits & 4) ; right pedal { ;Msgbox Right pedal pressed! ControlSend,,{]},VLC media player ;Increases playback speed by 0.1x increments } Else ; center pedal { ;MsgBox Center pedal pressed! ControlSend,,{Space},VLC media player ;Play/pause } } ; The following function should be uncommented & customized to your liking ; if you would like to utilize different actions upon releasing the foot ; pedal buttons ;ReleaseKey(bits) ;{ ; ToolTip Releasing %bits% ; SetTitleMatchMode, 2 ; If (bits & 1) ; MsgBox left pedal up! ; Else If (bits & 4) ; MsgBox Right pedal up! ; Else ; MsgBox Center pedal up! ;} Mem2Hex( pointer, len ) { A_FI := A_FormatInteger SetFormat, Integer, Hex Loop, %len% { Hex := *Pointer+0 StringReplace, Hex, Hex, 0x, 0x0 StringRight Hex, Hex, 2 hexDump := hexDump . hex Pointer ++ } SetFormat, Integer, %A_FI% StringUpper, hexDump, hexDump Return hexDump } ; Keyboards are always Usage 6, Usage Page 1, Mice are Usage 2, Usage Page 1, ; HID devices specify their top level collection in the info block RegisterHIDDevice(UsagePage,Usage) { ; local RawDevice,HWND RIDEV_INPUTSINK := 0x00000100 DetectHiddenWindows, on HWND := WinExist("ahk_class AutoHotkey ahk_pid " DllCall("GetCurrentProcessId")) DetectHiddenWindows, off VarSetCapacity(RawDevice, 8 + A_PtrSize) NumPut(UsagePage, RawDevice, 0, "UShort") NumPut(Usage, RawDevice, 2, "UShort") NumPut(RIDEV_INPUTSINK, RawDevice, 4, "UInt") NumPut(HWND, RawDevice, 8, "UPtr") Res := DllCall("RegisterRawInputDevices", "Ptr", &RawDevice, "UInt", 1, "UInt", 8 + A_PtrSize, "UInt") if (Res = 0) MsgBox, Failed to register for HID Device } InputMessage(wParam, lParam, msg, hwnd) { RID_INPUT := 0x10000003 RIM_TYPEHID := 2 SizeOfHeader := 8 + A_PtrSize + A_PtrSize SizeofRidDeviceInfo := 32 RIDI_DEVICEINFO := 0x2000000b DllCall("GetRawInputData", "Ptr", lParam, "UInt", RID_INPUT, "Ptr", 0, "UIntP", Size, "UInt", SizeOfHeader, "UInt") VarSetCapacity(Buffer, Size) DllCall("GetRawInputData", "Ptr", lParam, "UInt", RID_INPUT, "Ptr", &Buffer, "UIntP", Size, "UInt", SizeOfHeader, "UInt") Type := NumGet(Buffer, 0 * 4, "UInt") Size := NumGet(Buffer, 1 * 4, "UInt") Handle := NumGet(Buffer, 2 * 4, "UPtr") VarSetCapacity(Info, SizeofRidDeviceInfo) NumPut(SizeofRidDeviceInfo, Info, 0) Length := SizeofRidDeviceInfo DllCall("GetRawInputDeviceInfo", "Ptr", Handle, "UInt", RIDI_DEVICEINFO, "Ptr", &Info, "UIntP", SizeofRidDeviceInfo) VenderID := NumGet(Info, 4 * 2, "UInt") Product := NumGet(Info, 4 * 3, "UInt") ; tooltip %VenderID% %Product% if (Type = RIM_TYPEHID) { SizeHid := NumGet(Buffer, (SizeOfHeader + 0), "UInt") InputCount := NumGet(Buffer, (SizeOfHeader + 4), "UInt") Loop %InputCount% { Addr := &Buffer + SizeOfHeader + 8 + ((A_Index - 1) * SizeHid) BAddr := &Buffer Input := Mem2Hex(Addr, SizeHid) If (VenderID = 1523 && Product = 255) ; need special function to process foot pedal input ProcessPedalInput(Input) Else If (IsLabel(Input)) { Gosub, %Input% } } } }
As I am personally running the 32 bit version of AutoHotkey, I have not tested the 64 bit version of the above script.

trout19
New Cone
New Cone
Posts: 3
Joined: 27 Jul 2014 05:21

Re: Controlling VLC with a USB Foot Pedal (for Dictation, et

Postby trout19 » 27 Jul 2014 05:26

Hi - When I tried this, I got a message saying "Failed to register for HID Device". I'm not a programmer but I have played around with AutoHotKey to run macros and as a text expander. However, I don't know enough to know what the error message means. I'm leaning toward Windows 7 doesn't recognize the input device? But I'd like to see how to fix this in the AHK utility.

Thanks in advance,
Nancy

SumDood
New Cone
New Cone
Posts: 7
Joined: 21 Feb 2014 08:20

Re: Controlling VLC with a USB Foot Pedal (for Dictation, et

Postby SumDood » 28 Jul 2014 22:01

If you're using a different foot pedal, you may need to change the #'s in the RegisterHIDDevice line, though I really don't know what those #'s are. First, though, I would try a different version of AHK. Personally, I'm using the 32-bit version 1.0.48.05.

trout19
New Cone
New Cone
Posts: 3
Joined: 27 Jul 2014 05:21

Re: Controlling VLC with a USB Foot Pedal (for Dictation, et

Postby trout19 » 29 Jul 2014 03:23

Hey - it did turn out that it was the wrong version of AHK - I found the latest 64 bit at ahkscript.org and it worked great.

Have you had any problems with the caps lock getting stuck? Every once in a while, the caps lock will keep coming on when pressing the play pedal. Then I have to close VLC, bring up Window's On-screen keyboard, click the up arrow twice, then restart VLC and go back to where I was in the playback. The convenience of the foot pedal makes all that worth it, but it still is kind of a pain and I wish I knew how to stabilize, for lack of a better word, the program.

Thanks,
Nancy

SumDood
New Cone
New Cone
Posts: 7
Joined: 21 Feb 2014 08:20

Re: Controlling VLC with a USB Foot Pedal (for Dictation, et

Postby SumDood » 29 Jul 2014 04:10

I haven't had that specific problem, but sometimes the foot pedal doesn't do what it's supposed to do. When that happens, I right-click on the AHK icon in the system tray and choose "Reload This Script." That usually fixes the problem for me.

Glad you got the device registration thing working. :)

trout19
New Cone
New Cone
Posts: 3
Joined: 27 Jul 2014 05:21

Re: Controlling VLC with a USB Foot Pedal (for Dictation, et

Postby trout19 » 29 Jul 2014 04:43

Oh thank goodness - I am so glad you were available to tell me about reloading the script. I just happened to be in the middle of closing VLC and restarting again when I saw your message.

Thanks a bunch!

SumDood
New Cone
New Cone
Posts: 7
Joined: 21 Feb 2014 08:20

Re: Controlling VLC with a USB Foot Pedal (for Dictation, et

Postby SumDood » 29 Jul 2014 07:18

No problem. Glad I could help.

stanbondinc
New Cone
New Cone
Posts: 4
Joined: 21 Apr 2015 06:43

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby stanbondinc » 21 Apr 2015 06:52

Will this work on Video playback? I use VLC to play video guitar lessons, & the footpedal function would be very helpful. I too purchased software that stopped working & the outfit I bought it from is no longer active (PCDictate.com)

Champeau
New Cone
New Cone
Posts: 1
Joined: 22 Apr 2015 22:42

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby Champeau » 22 Apr 2015 22:44

Thank you for this script! I had to add:

SetKeyDelay for the left and right pedals to respond consistently.

I am still trying to figure out how to do a loop with the pedals. I would prefer it to keep doing 3 second jumps while the pedal is pressed rather than having to keep pressing it.

Hermosa.tabby
New Cone
New Cone
Posts: 5
Joined: 23 May 2015 05:33

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby Hermosa.tabby » 23 May 2015 06:41

I think the issue with this may be how key peripherals are encoded into the system. Having various lines running at the same time and key variables getting stuck in halfway between 1 key and the next. The answer is to not send these commands through the keyboard and possibly for a dev to build an extension to address the controls on a somewhat lower level. You have to consider all the translation going through the machine from footpress, to script, to keyboard driver to character printing. This foot pedal should be interpreted more like a midi signal as a raw value.
I can possibly take on this as a summer project if no one else wants to depending on the price of these foot pedals (to troubleshoot and alpha test)Peripherals are where I eventually want to be working. I will need to look through the source code and see where the applicable events are and if there is anything I could use to latch a new control interface onto. If any other devs who are familiar with vlc's source and may have an idea of where this functions are located, it may save me a bit of time. I am unfamiliar with code integration of vlc plug-ins and their limitations within the main program, but if I can grab into those values, and write a plugin to make those key values footswitch compatible, it would be a great addition to vlc and it's users.

shouav
New Cone
New Cone
Posts: 1
Joined: 06 Oct 2015 12:42

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby shouav » 06 Oct 2015 12:47

I'd be really grateful if someone could tell me how to do this. I don't know how to insert script or program so I need a simple response. thanks so much in advance. :oops:

gavijon
New Cone
New Cone
Posts: 2
Joined: 28 Oct 2015 11:10

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby gavijon » 28 Oct 2015 11:24

1. Download and install (real) free PedalWare software from AltoEdge http://www.altoedge.com/pedalware/
2. In options select your pedal type (VEC Pedals USB ?) and make sure that the software recognizes your pedal (indicator on lower right part of the window)
3. Configure actions; Center-Send Key Space Left-Send Key ALt+Left Right-Send Key Alt+Right
4. Run VLC, pressing center pedal is Pause/Play, Right/Left is 10 seconds back or forward
5. If you're installing the SW in Windows 8, 8.1 or 10 run both the installation program (pedalwaresetup) AND the program itself (pedalware) in Windows 7 compatibility mode

Mario

gavijon
New Cone
New Cone
Posts: 2
Joined: 28 Oct 2015 11:10

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby gavijon » 28 Oct 2015 15:00

UPDATE:
The fact that PedalWare emulates key press creates a problem.
If the VLC window is not in focus (i.e typing in Word) the keys are injected into the document instead of VLC.
Changing the focus from Word to VLC and back to Word slows down the dictation process.
Will try to find a way connecting PedalWare output ONLY to VLC
Any ideas ?

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby Jean-Baptiste Kempf » 30 Oct 2015 18:21

Use the global hotkeys of VLC.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

dylan.hart
New Cone
New Cone
Posts: 1
Joined: 10 Aug 2016 19:20

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby dylan.hart » 10 Aug 2016 19:23

Just wanted to say thank you to SumDood for the script. Worked immediately. Thanks for sharing!

dct
New Cone
New Cone
Posts: 1
Joined: 26 Nov 2020 18:00

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby dct » 26 Nov 2020 18:03

Thank you for this.

FWIW I made a modification to Play/Pause to also rewind 3 seconds, because I typically need to rehear and get context when I pause;

Else ; center pedal
{
;MsgBox Center pedal pressed!
; new line to rewind a couple of seconds
ControlSend,,{=}+{Left},VLC media player ;Normalizes playback speed, and rewinds 3 seconds
ControlSend,,{Space},VLC media player ;Play/pause
}

Michael.Long
New Cone
New Cone
Posts: 1
Joined: 11 Feb 2021 04:03

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby Michael.Long » 11 Feb 2021 04:06

This script works with the Infinity IN-FTRUSB Foot Pedal as well. It will save our secretaries a lot of trouble transcribing committee meetings when FTR's audio is not quite up to par. We can use our SLIQ recordings.

Montaillou
New Cone
New Cone
Posts: 1
Joined: 16 Apr 2021 01:22

Re: Controlling VLC with a USB Foot Pedal (for Dictation, etc.)

Postby Montaillou » 16 Apr 2021 01:25

Hi sct,

Thanks for posting this addition to the script:
Thank you for this.

FWIW I made a modification to Play/Pause to also rewind 3 seconds, because I typically need to rehear and get context when I pause;

Else ; center pedal
{
;MsgBox Center pedal pressed!
; new line to rewind a couple of seconds
ControlSend,,{=}+{Left},VLC media player ;Normalizes playback speed, and rewinds 3 seconds
ControlSend,,{Space},VLC media player ;Play/pause
}
I'm a very experienced transcriber, but an ignoramus when it comes to scripting. Could you (or someone) let me know exactly where in the 64-bit version of the script posted above I should add these lines?

Many thanksg again, Montaillou.


Return to “Contribute and help the VideoLAN project”

Who is online

Users browsing this forum: No registered users and 5 guests