AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: October 12th, 2011, 6:01 pm 
Hi,
I did a little bit of research in the forum but didn't find exactly what I needed.

I need to make one of my mouse buttons show a dropdown menu of "commands". When I click on one of these "commands" it sends a specific keystroke.

For example, I press 'mouse 4'. A list is displayed, first item of the list says "Line". When I click on "Line", AutoHotkey sends the keystroke 'L' (as if pushing the L key on the keyboard).

This is what I have so far. The problem with this is that it sends "Line" instead of 'L':

Menu, dsc, Add, Line, mymenu
Return

XButton1::
Menu, dsc, Show
Return

mymenu:
sleep 100
SendInput %A_ThisMenuItem%{ENTER}
Return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2011, 6:48 pm 
Offline

Joined: June 18th, 2006, 8:47 am
Posts: 346
Location: Phoenix, AZ
Here is one way I've seen this done. It permits any label to execute any code. Depending on what you intend to send you may not need separate subroutines.

Well you could do without the subroutines and do if statements...

Code:
Menu, dsc, Add, Line, mymenu
Menu, dsc, Add, Example, mymenu
Return

XButton1::
Menu, dsc, Show
Return

mymenu:
sleep 100
GoSub, %A_ThisMenuItem%
Return

Line:
Send, L{Enter}
return

Example:
Send, Example{Enter}
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2011, 7:26 pm 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
Friendly wrote:
This is what I have so far. The problem with this is that it sends "Line" instead of 'L':

Correct. The variable A_ThisMenuItem contains the full text of the menu item choosen.
So if you want to get only the letter L from the menu Line you must extract the first letter from the var or create several subroutines, as keybored suggest in his post, to do the work for you. So said, if you only want to paste the first letter of the menu item clicked you can try this:
Code:
Menu, dsc, Add, First Item, mymenu
Menu, dsc, Add, Line, mymenu
Menu, dsc, Add, Example, mymenu
Menu, dsc, Add, Another, mymenu
Menu, dsc, Add, The Last, mymenu
Return

XButton1::
   Menu, dsc, Show
Return

mymenu:
   sleep 100
   Send, % SubStr(A_ThisMenuItem,1,1) "{Enter}"
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2011, 8:17 pm 
Thanks keybored and Odlanir, it worked great! :D

Now, if I wanted that when I click 'Line' it did other commands such as "^!{UP}"... would I need to do that by creating a subroutine for each menu item?

I was hoping there was a simpler way, thanks!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2011, 8:44 pm 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
Friendly wrote:
Now, if I wanted that when I click 'Line' it did other commands such as "^!{UP}"... would I need to do that by creating a subroutine for each menu item?

not necessarily.You can use a single soubroutine to handle all the variuos entry in your menu by testing the MenuItem name.
Code:
mymenu:
   sleep 100
   if ( A_ThisMenuItem = "First Item") {
      tooltip, First item choosen
   } else if ( A_ThisMenuItem = "Line") {
      tooltip, Second item choosen
   } else if ( A_ThisMenuItem = "Example") {
      tooltip, Third item choosen
   } else if ( A_ThisMenuItem = "Another") {
      tooltip, Fourth item choosen
   } else if ( A_ThisMenuItem = "The Last"){
      tooltip, Last item choosen >>>>%A_ThisMenuItem%<<<<
   } else {
      tooltip,
   }   
Return
 


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, Google Feedfetcher, Yahoo [Bot] and 16 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