AutoHotkey Community

It is currently May 27th, 2012, 12:43 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Context AHK menu
PostPosted: September 26th, 2005, 5:18 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
Is it possible to display a context menu when the user right clic in the window of an app. And if this app has already context menus, witch one is displayed, the AHK one (if it's possible), or the app one.
So is it possible to have something like :
Code:
RButton::
IfWinActive, Myapp
   Display an AK "context" menu
return

Thanks by advance for your answers.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 6:02 pm 
Offline

Joined: February 14th, 2005, 10:54 am
Posts: 447
Location: Texas, Usa
Why dont you try it? your but one step from your answer, a test.

_________________
my lame sig :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 6:22 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
You're right, Invalid User. But I asked the question thinking it is not possible, but without making any try !!!
So I take the help file example and try to accomodate it, and I have :
Code:
RButton::
IfWinActive, Bloc-notes

; This next example is a working script to demonstrate some of the various menu commands.
{
menu, context, add ; separator
menu, context, add, TestToggle&Check
menu, context, add, TestToggleEnable
menu, context, add, TestDefault
menu, context, add, TestStandard
menu, context, add, TestDelete
menu, context, add, TestDeleteAll
menu, context, add, TestRename
menu, context, add, Test
return
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TestToggle&Check:
menu, context, ToggleCheck, TestToggle&Check
menu, context, Enable, TestToggleEnable ; Also enables the next test since it can't undo the disabling of itself.
menu, context, add, TestDelete ; Similar to above.
return

TestToggleEnable:
menu, context, ToggleEnable, TestToggleEnable
return

TestDefault:
if default = TestDefault
{
   menu, context, NoDefault
   default =
}
else
{
   menu, context, Default, TestDefault
   default = TestDefault
}
return

TestStandard:
if standard <> n
{
   menu, context, NoStandard
   standard = n
}
else
{
   menu, context, Standard
   standard = y
}
return

TestDelete:
menu, context, delete, TestDelete
return

TestDeleteAll:
menu, context, DeleteAll
return

TestRename:
if NewName <> renamed
{
   OldName = TestRename
   NewName = renamed
}
else
{
   OldName = renamed
   NewName = TestRename
}
menu, context, rename, %OldName%, %NewName%
return

Test:
MsgBox, You selected "%A_ThisMenuItem%" in menu "%A_ThisMenu%".
return


But this don't work at all. What can I do to make it work ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 7:35 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
There were a few issues:

* missing menu, <name>, show command
* menu was built each time hotkey was activated, resulting in extra separator lines added each time. you should either build the menu once in the autoexecute section or conditionally inside a subroutine, or rebuild and destroy the menu between each call (e.g., for dynamic menus).
* dead key: RButton

Try the following code (tested with Notepad):

Code:
menu_context := false
return

$RButton::
   IfWinActive, Untitled - Notepad
   
   ; This next example is a working script to demonstrate some of the various menu commands.
   {
      if ( ! menu_context )
      {
         menu, context, add ; separator
         menu, context, add, TestToggle&Check
         menu, context, add, TestToggleEnable
         menu, context, add, TestDefault
         menu, context, add, TestStandard
         menu, context, add, TestDelete
         menu, context, add, TestDeleteAll
         menu, context, add, TestRename
         menu, context, add, Test
         
         menu_context := true
      }
      
      Menu, context, Show
   }
   else
      Send, {RButton Down}
return

$RButton Up::
   Send, {RButton Up}
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TestToggle&Check:
menu, context, ToggleCheck, TestToggle&Check
menu, context, Enable, TestToggleEnable ; Also enables the next test since it can't undo the disabling of itself.
menu, context, add, TestDelete ; Similar to above.
return

TestToggleEnable:
menu, context, ToggleEnable, TestToggleEnable
return

TestDefault:
if default = TestDefault
{
   menu, context, NoDefault
   default =
}
else
{
   menu, context, Default, TestDefault
   default = TestDefault
}
return

TestStandard:
if standard <> n
{
   menu, context, NoStandard
   standard = n
}
else
{
   menu, context, Standard
   standard = y
}
return

TestDelete:
menu, context, delete, TestDelete
return

TestDeleteAll:
menu, context, DeleteAll
return

TestRename:
if NewName <> renamed
{
   OldName = TestRename
   NewName = renamed
}
else
{
   OldName = renamed
   NewName = TestRename
}
menu, context, rename, %OldName%, %NewName%
return

Test:
MsgBox, You selected "%A_ThisMenuItem%" in menu "%A_ThisMenu%".
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 9:02 pm 
Offline

Joined: December 15th, 2004, 10:24 pm
Posts: 303
Location: United States
Nemroth wrote:
And if this app has already context menus, witch one is displayed, the AHK one (if it's possible), or the app one.

Solution (tested with Notepad):
Code:
RButton::

IfWinActive, Untitled - Notepad
{
   Loop 5
   {
      sleep 50
      if not GetKeyState("RButton", "p")
      {
         MouseClick, R , , , , 0
         EXIT
      }
   
      if A_Index = 5
      { ; This next example is a working script to demonstrate some of the various menu commands.
         if ( ! menu_context )
         {
            menu, context, add ; separator
            menu, context, add, TestToggle&Check
            menu, context, add, TestToggleEnable
            menu, context, add, TestDefault
            menu, context, add, TestStandard
            menu, context, add, TestDelete
            menu, context, add, TestDeleteAll
            menu, context, add, TestRename
            menu, context, add, Test
                     
            menu_context := true
         }
             
         Menu, context, Show
      }
   }
}
else
   Send, {RButton}

KeyWait RButton

return


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TestToggle&Check:
menu, context, ToggleCheck, TestToggle&Check
menu, context, Enable, TestToggleEnable ; Also enables the next test since it can't undo the disabling of itself.
menu, context, add, TestDelete ; Similar to above.
return

TestToggleEnable:
menu, context, ToggleEnable, TestToggleEnable
return

TestDefault:
if default = TestDefault
{
   menu, context, NoDefault
   default =
}
else
{
   menu, context, Default, TestDefault
   default = TestDefault
}
return

TestStandard:
if standard <> n
{
   menu, context, NoStandard
   standard = n
}
else
{
   menu, context, Standard
   standard = y
}
return

TestDelete:
menu, context, delete, TestDelete
return

TestDeleteAll:
menu, context, DeleteAll
return

TestRename:
if NewName <> renamed
{
   OldName = TestRename
   NewName = renamed
}
else
{
   OldName = renamed
   NewName = TestRename
}
menu, context, rename, %OldName%, %NewName%
return

Test:
MsgBox, You selected "%A_ThisMenuItem%" in menu "%A_ThisMenu%".
return
Click the RButton normally for the normal application menu. Hold it down longer to invoke the custom menu.

_________________
1) The Open Source Definition http://www.opensource.org/docs/definition_plain.php

2) Intuitive. Logical. Versatile. Adaptable. <<AutoHotkey>>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 9:15 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
Thanks a lot, shimanov and Decarlo110. Your examples are very good and very instructives, especially for me the possibility to have the default context menu of the app and an other available toghether. I will study them with attention.
On the AHK forum, there is definitively a very good support...
Thanks again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 10:04 pm 
Offline

Joined: September 25th, 2005, 4:31 pm
Posts: 610
Decarlo110 wrote:
Click the RButton normally for the normal application menu. Hold it down longer to invoke the custom menu.


Good solution -- have the best of both worlds. Only one issue with RButton drag. Try the following code:

Code:
menu_context := false
return

activate_custom_menu:
   SetTimer, activate_custom_menu, off

   if ( ! menu_context )
   {
    menu, context, add ; separator
    menu, context, add, TestToggle&Check
    menu, context, add, TestToggleEnable
    menu, context, add, TestDefault
    menu, context, add, TestStandard
    menu, context, add, TestDelete
    menu, context, add, TestDeleteAll
    menu, context, add, TestRename
    menu, context, add, Test
   
    menu_context := true
   }
   
   Menu, context, Show
return

$RButton::
   ifWinActive, Untitled - Notepad
      SetTimer, activate_custom_menu, 500
   else
      Send, {RButton Down}
return

$RButton Up::
   SetTimer, activate_custom_menu, off

   ifWinActive, Untitled - Notepad
      Send, {RButton Down}{RButton Up}
   else
      Send, {RButton Up}
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TestToggle&Check:
menu, context, ToggleCheck, TestToggle&Check
menu, context, Enable, TestToggleEnable ; Also enables the next test since it can't undo the disabling of itself.
menu, context, add, TestDelete ; Similar to above.
return

TestToggleEnable:
menu, context, ToggleEnable, TestToggleEnable
return

TestDefault:
if default = TestDefault
{
   menu, context, NoDefault
   default =
}
else
{
   menu, context, Default, TestDefault
   default = TestDefault
}
return

TestStandard:
if standard <> n
{
   menu, context, NoStandard
   standard = n
}
else
{
   menu, context, Standard
   standard = y
}
return

TestDelete:
menu, context, delete, TestDelete
return

TestDeleteAll:
menu, context, DeleteAll
return

TestRename:
if NewName <> renamed
{
   OldName = TestRename
   NewName = renamed
}
else
{
   OldName = renamed
   NewName = TestRename
}
menu, context, rename, %OldName%, %NewName%
return

Test:
MsgBox, You selected "%A_ThisMenuItem%" in menu "%A_ThisMenu%".
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 10:17 pm 
Offline

Joined: September 7th, 2004, 9:20 pm
Posts: 275
Location: France
Thanks, shimanov. I see the improvement. Very interesting.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2010, 5:32 am 
..Is there is no way around the RButton drag issue??

shimanov wrote:
Good solution -- have the best of both worlds. Only one issue with RButton drag.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, jrav, MSN [Bot] and 24 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group