3

I want to use Alt+d to trigger Delete.

!d::Send, {delete}

This works almost everywhere except in explorer. Nothing happens when select a file and press Alt+d. Why is that?

Environment: latest AutoHotKey, Windows 10-64bit

aj3423
  • 2,003
  • 3
  • 32
  • 70
  • Alt+D is used to focus on the address bar. Not sure if you can override that... Does your AHK actually prevent the address bar from being selected? – Adam Plocher Feb 19 '19 at 09:58
  • The address bar isn't selected if I press Alt+D, the focus is still on the selected file. – aj3423 Feb 19 '19 at 10:09
  • I can confirm that it doesn't work with file explorer in Win10. Interestingly, it does seem to trigger a ctrl press (at least with right alt key). I don't know why to either of those. I also tried many variations with no success. Sorry, I do not have a solution for you. – EJE Feb 19 '19 at 12:33

1 Answers1

4

Try

!d::
    IfWinActive ahk_class CabinetWClass ; explorer
    {
        ; The control retrieved by this command is the one that has keyboard focus
        ControlGetFocus, FocusedControl, A  ; A means the active window
        ; MsgBox %FocusedControl%
        If FocusedControl contains DirectUIHWND,SysListView
             SendInput, {AppsKey}d
        else
            Send, {delete}
    }
    else
        Send, {delete}
return

https://autohotkey.com/docs/commands/ControlGetFocus.htm

user3419297
  • 9,537
  • 2
  • 15
  • 24
  • 2
    Why? Please add some explanation to your code such that others can learn from it – Nico Haase Feb 19 '19 at 11:36
  • It's not about me specially not understanding something. But as you are a long-time user on SO, you should know that good answers contain explanations such that others can learn from it. If these commands are so simple, there must be a reason the OP asked here about it instead of just writing that down – Nico Haase Feb 19 '19 at 12:48
  • @user3419297 The `AppsKey` won't work when delete any text in explorer, such as edit when rename file, in address bar, or in search filter. Is it possible to send raw Delete key, that should work for all these. – aj3423 Feb 19 '19 at 14:37
  • @aj3423, maybe we can find an answer to this question, if you explain why you prefer the Alt+d combination instead of pressing the Delete key for deleting a file or text in explorer (It will narrow down the possible solutions). – user3419297 Feb 19 '19 at 15:04
  • Hmm. Perhaps holding "`alt`" and "`appskey`" together doesn't work when pressed at the same time (just try pushing them at the same time in explorer). So, maybe try putting in a "`keywait`" statement in to wait until alt is released before sending appskey? – PGilm Feb 19 '19 at 17:45
  • @user3419297 The 'Delete' key is too far away, programmers don't like move their hands away from the main keyboard area when working, there're tools like 'vim'/'emacs' for editor, 'vimium' for browser, and now AHK for explorer :) – aj3423 Feb 19 '19 at 18:16
  • @user3419297 The 'SysListView' doesn't work, but 'DirectUIHWND3' works. `MsgBox %FocusedControl%` shows 'DirectUIHWND3' – aj3423 Feb 19 '19 at 19:25
  • OK, I edited the answer to include DirectUIHWND and SysListView (SysListView works for me and maybe for other users too) It can be changed in another OS edition. – user3419297 Feb 19 '19 at 19:47