1

I'm trying to trigger a call to a program directly from Windows Explorer with the selected files as parameter, and this with a key push (on F12 or Ctrl+E for example). The same kind of action as when you select more than one file and press F2 to rename them all. I was looking in the registry but with no success.

For example, when I open my src folder and select a few JS files I have to right-click on a file, select "Send To", and select the right shortcut to my "programme.exe" software (transcription from JS, import of a few environmental vars, etc.). It would be helpful if I could simply press Ctrl+E to transcript and edit those selected files.

An other similar thing I'm looking for is to press F12 and edit all my selected files (it's easier for me to use a keyboard than a mouse).

I'm on Windows 10 and don't think this is linked to desktop shortcuts or anything like that. I should have been more explicit; the external calls are done, but the link between the keyboard shortcut and these calls is the part I'm trying to deal with.

I've already created an AutoIt script that does this, but it should be possible within the Windows Explorer itself (and only when it's needed, not looping a script infinitely I mean), shouldn't it?

#include <Array.au3>
#include <WinAPI.au3>

; Init - stop
Global $stop = False
HotKeySet("{F4}", "stop")
Func stop()
    If $stop Then Exit
    $stop = True
EndFunc

; Init - trigger
Global $trigger = False
HotKeySet("^t", "trigger")
Func trigger()
    $trigger = True
EndFunc

; Event loop
While Not $stop
    Sleep(100)
    If $trigger Then
        action()
        $trigger = False
    EndIf
WEnd

Func action()
    ConsoleWrite(@CRLF)
    ; Check active window (explorer only)
    Local $handle = WinGetHandle("[ACTIVE]"), $class = _WinAPI_GetClassName($handle)
    ConsoleWrite("- Window:"&$class&" ")
    If $class <> "CabinetWClass" Then Return
    ; Get object linked to window
    Local $shell = ObjCreate("Shell.Application"), $window = 0
    For $object In $shell.Windows()
        If $object.HWND() = $handle Then
            $window = $object
            ExitLoop
        EndIf
    Next
    If $window = 0 Then Return
    ; Check active component (right filelist panel only)
    Local $control = ControlGetFocus($handle)
    If $control <> "DirectUIHWND3" Then Return
    ; Get selection (files selected in the right panel)
    Local $selected[1] = [0]
    For $element In $window.Document.SelectedItems()
        If $element.IsFolder Or $element.IsLink Then ContinueLoop
        Local $path = $element.Path
        For $i = 1 To $selected[0]
            If $path = $selected[$i] Then ContinueLoop 2
        Next
        $selected[0] = $selected[0]+1
        ReDim $selected[$selected[0]+1]
        $selected[$selected[0]] = $path
    Next
    ; Action : ###############################
EndFunc
user4157124
  • 2,809
  • 13
  • 27
  • 42
  • Look I don't know AutoIt but can't you just call`action()` within `trigger()` instead of looping forever?? :) I'm pretty sure there is no way to add shortcuts to explorer itself, if that's what you were looking for, you have to use global hotkeys. – gbr Jul 07 '17 at 13:56
  • 1
    Ok that was exactly what I wanted to do, add directly a hotkey in explorer (by registry like the custom menus); if it's impossible, I'll keep my script. Thanks for your answer. – Aurélien Achat Jul 08 '17 at 00:18
  • And the use of `action` outside `trigger` is an simple way to avoid parallel launches if you push many times Ctrl+T. With AutoIt, the script must loop in order to keep triggering the hotkey, so a while/wend is mandatory, at least I can use it as a mutex ^^ – Aurélien Achat Jul 08 '17 at 00:28
  • _And the use of action outside trigger is an simple way to avoid parallel launches if you push many times Ctrl+T._ Ok all right but, sorry, `trigger()` still gets called every time you press the hotkey, right, even if you're inside the loop? So wouldn't it be simpler and more efficient to do: `Func trigger()`↵ `Local Static $DoingAction = False`↵ `If Not $DoingAction Then`↵ `$DoingAction = True`↵ `action()`↵ `$DoingAction = False`↵ `EndIf`↵ `EndFunc` (replace the '↵' with linebreaks - apparently there's no way to put multiple statements in a single line in AutoIt). – gbr Jul 10 '17 at 13:17
  • _the script must loop in order to keep triggering the hotkey, so a while/wend is mandatory_ Ok, if you say so I surely believe you... with that sleep inside it will probably not consume a lot of resources anyway – gbr Jul 10 '17 at 13:23
  • I was pretty sure there were already questions about adding hotkeys to explorer, but I can't find them now. [assigning-keyboard-shortcut-to-get-path-of-selected-item-in-windows-explorer](https://stackoverflow.com/q/2701298) is related though . – gbr Jul 10 '17 at 13:25

1 Answers1

0

Froggy! :o) I can tell you that your English is a heck of a lot better than my French, so don't even worry about that.

I think what you're going to need to do is to create a custom macro or VBScript to open the files using your desired EXE. I'm not very good with VBScript myself, so that part I can't help with.

As for the rest of your request, there are instructions on the Microsoft site for how to do this. I will paste them here just in case the link ever changes:

Step 1: Download the current version of IntelliType software

Step 2: Start the Keyboard wizard, and change the assignments

  1. Open the Keyboard item in Control Panel.

    • In Windows 7 or in Windows Vista, click Start the Start button , type keyboard in the Start Search box, and then click Keyboard (or Microsoft Keyboard) in the Programs list.
    • In Windows XP and earlier versions of Windows, click Start, click Run, type Control keyboard, and then click OK.
  2. On the Key Settings tab, select the key that you want to change.

  3. To change the command or the program assignment, click Configure. To change or to assign a macro to the key, click Assign/Manage Macro.
  4. Select the appropriate options, and then follow the instructions.

Notes

  • You can specify that a program open to a specific document, Web site, or other item by adding the appropriate parameter. For example:

    • iexplore.exe http://www.msn.com: Starts Microsoft Internet Explorer, and opens the MSN.com Web site
    • word.exe mydoc.doc: Starts Microsoft Word, and opens the mydoc file
  • Use Restore Defaults to remove all customized settings, and restart all assignments.

  • Under Custom Key Settings, you can rename each bank by using Options, or you can add a program for custom key assignments for that program by using Add.

  • Macros can be assigned or changed by using the Assign/Manage Macro button. See Help for more information.


This StackOverflow question might give you a little more guidance as well.

Additionally, this question on another website shows that it works for VBScripts, and gives an example of a VBScript. I won't bother copy/pasting it all, it's just backup for what I've written above.

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117