Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Invoking directly ContextMenu of Files and Folders


  • Please log in to reply
62 replies to this topic
Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
It'll invoke the context menu of a file-system/virtual file or folder, without opening the explorer window.

DOWNLOAD ShellContextMenu.ahk.

Hardeep
  • Members
  • 87 posts
  • Last active: Sep 12 2007 06:40 PM
  • Joined: 02 Jul 2006
I love these tricks you do with COM :D

Thanks

Thalon-nli
  • Guests
  • Last active:
  • Joined: --
Thanks Sean!
That's what I actually was looking for :)

LBJ
  • Members
  • 24 posts
  • Last active: Apr 04 2011 06:18 AM
  • Joined: 03 May 2007
I've played with this for most of the afternoon now and I've looked at a lot of incomplete pieces of related information, but I can't make this work with a group of selected files rather than just one item.

Has anyone managed to expand on this to work with a set of files? If so, how did you mange it?

sabot7726
  • Members
  • 69 posts
  • Last active: Aug 12 2013 03:29 AM
  • Joined: 27 Nov 2006
Is it possible to add a portion of ahk scripting to the right click context menu?

For example:
Let's say I have a script called copypaste.ahk that copies and pastes something into another program. I would want to highlight a word and rightclick, then see an option there called copypaste where it can do the copy/paste operation.

Is that possible yet? :)

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Is it possible to add a portion of ahk scripting to the right click context menu?

You're a bit vague on what you'd like to do. If you meant the explorer's context menu, you can do it by adding Shell Menu item, or by writing a ContextMenuHandler dll. If you meant the context menu of this script, you can do it without dll even at runtime, but I have no desire to release any further work on this. You may tweak the script yourself to your need as all needed ones for that were already put to the script.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Has anyone managed to expand on this to work with a set of files? If so, how did you mange it?

How do you think Explorer does it? You can exactly do the same with the script.

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
Once again, you have provided a great script for the community. I realize this is a bit old, but I just wanted to say thanks.
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

Superfraggle
  • Members
  • 1019 posts
  • Last active: Sep 25 2011 01:06 AM
  • Joined: 02 Nov 2004
Can this be modified to directly launch a specific menuitem of the context menu.

Similar to SHObjectProperties
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Can this be modified to directly launch a specific menuitem of the context menu.

You can use InvokeVerb(Ex) or DoIt for that.
<!-- m -->http://msdn.microsof...y/bb787816.aspx<!-- m -->
<!-- m -->http://msdn.microsof...y/bb774170.aspx<!-- m -->

There exist examples utilizing them in the forum. You may search.

pacifika
  • Members
  • 26 posts
  • Last active: Dec 19 2012 12:01 AM
  • Joined: 27 Oct 2008
Could someone please post a small ahk example showing how to utilize this script as I cannot get it to work, my app just loses focus and then regains it.
Cheers

pajenn
  • Members
  • 391 posts
  • Last active: Feb 06 2015 07:57 AM
  • Joined: 07 Feb 2009
Thank you for the scripts. I've added them to my C:\Program Files\AutoHotkey\Lib directory. I'm using the function to first invoke the context menu for a given file, then send keyboard inputs into the menu to navigate to the desired choice. Here's the code:

DetectHiddenWindows, On  ; not sure if necessary
DetectHiddenText, On  ; not sure if necessary

ShellContextMenu("C:\test_file.txt")
Sleep, 200 ; to give conext menu time to pop-up
Send, {DOWN 12}{RIGHT}{DOWN 6}{ENTER} ; to select item
return

Problems:

1. The context menu for test_file.txt pops up next to the mouse cursor, but the "Send" commands do not go into it. I can manually select the option I want and it works though (in the attached pic I manually pressed down x 12, right, down x 6 to highlight "copy content."

2. Not all context menu items are included. The second pic shows the menu when I manually right-click on test_file.txt (incl. FastCopy, Scan with Rising, a-squared,...) - however, this is just fyi, as the menu I want is present.

Any advice would be appreciated - I'm new to AHK so even if I'm leaving out something obvious, I might not realize it.

Posted Image Posted Image

Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet


Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

1. The context menu for test_file.txt pops up next to the mouse cursor, but the "Send" commands do not go into it. I can manually select the option I want and it works though (in the attached pic I manually pressed down x 12, right, down x 6 to highlight "copy content."

The Send part will never run until the menu is closed. You have to use SetTimer for that.

Not all context menu items are included. The second pic shows the menu when I manually right-click on test_file.txt (incl. FastCopy, Scan with Rising, a-squared,...) - however, this is just fyi, as the menu I want is present.

I suppose there was a problem to load/communicate with the corresponding ContextMenuHandler dlls. I can't tell the details unless I test them myself.

pajenn
  • Members
  • 391 posts
  • Last active: Feb 06 2015 07:57 AM
  • Joined: 07 Feb 2009
Just to follow up, I ended up using the status bar text to access the FileMenu Tools. However, I used ShellContextMenu for a script to find what's locking my drive, for example, when a flash drive refuses to eject. Below is the main script - I use AltGr+U followed by the letter of the drive I want to unlock. I'm using WhoLockMe for the underlying unlocker, but Unlocker is good too (both are free):

<^>!u::
Input, locked, T3 L1, {esc}, c, i, j, k, l, z
SetKeyDelay, -1
Run WhoLockMe.ahk
Sleep, 500
if locked = c
  ShellContextMenu("C:\")
else if locked = i
  ShellContextMenu("I:\")
else if locked = j
  ShellContextMenu("J:\")
else if locked = k
  ShellContextMenu("K:\")
else if locked = l
  ShellContextMenu("L:\")
else if locked = z
  ShellContextMenu("Z:\")
return

Here's my WhoLockMe.ahk script with SetTimer. It uses MenuSelectItem function from the linked post by Lexikos with UseMouse = True. (With UseMouse = False the function sometimes selects the context menu item above the one I specify...)

#Persistent
SetTimer, WhoLockMe, 500
return

WhoLockMe:
IfWinNotExist, ahk_class #32768
    return
SetTimer, WhoLockMe, Off  ;timer off if context menu detected
MenuSelectItem("Who Lock Me ? ...")
GoSub, WhoLockExit
return

WhoLockExit:
Sleep, 1000
ExitApp
return

Not sure you need the WhoLockExit subroutine in this case, but I needed it to access submenus with some other context menu scripts. Again, this seems to work fine for me, but I have only used it a little bit...

Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet


Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Just to follow up, I ended up using the status bar text to access the FileMenu Tools.

I don't know how you use it, however, you can obtain the status bar help text of menu item using
VarSetCapacity(sHelp,63)
DllCall(NumGet(NumGet(1*pcm)+20), "Uint", pcm, "Uint", idCommand, "Uint", GCS_HELPTEXTA:=1, "Uint", 0, "str", sHelp, "Uint", 64)	; GetCommandString
Just FYI.