Detect left vs right click on a CTB

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
klownboy
Posts: 4424
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7462 at 100% 2560x1440

Detect left vs right click on a CTB

Post by klownboy »

Is there someway to detect whether a left click was made vs a right click on a CTB. I have some situations where I would like the menu items seen on a CTB to be exactly the same on either a L click or R click. However the actions would be modified if you right clicked vs left clicked. Obviously, this could be accomplished by 2 separate scripts, but I would like to be able to accomplish this in one script. I've used hidden labels in scripts but that just doesn't accomplish what I'd like to do.

The script would essentially be a menu list of different actions and look the same whether you L or R clicked (so visually they'd look identical), but inside the script itself the "sub" actions would be different if I L clicked vs R clicked.

Any ideas? I could a see a number of great uses for this capability. In searching the forum I saw that kiwichick hit apon something similar but asked in a differrent way here: http://www.xyplorer.com/xyfc/viewtopic. ... ctb#p77739
If not, could this be a potential wish list item?
Thanks,
Ken

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Detect left vs right click on a CTB

Post by Stefan »

klownboy wrote:Is there someway to detect whether a left click was made vs a right click on a CTB.
Any CTB has the option to execute an script for an left and an right click on that button.

An possible leftClick.xys could call the main.xys with label leftclicked, and the rightClick.xys visa versa.

That hidden script "_leftclicked"
could set an global variable like "gVar_Click"
and utilize an >sub "main"< command to jump to the main script.

Example:

leftClick.xys
load "main.xys", "_leftclicked"

rightClick.xys
load "main.xys", "_rightclicked"

main.xys
"main"
  global gVar_Click;
  msg gVar_Click;
  if(gVar_Click == "L") {
      msg "executed by left click";
      command2;
      command3;
  }else{msg "launched by an right click";}

"_leftclicked"
  global gVar_Click;
  gVar_Click = "L";
  sub "main";

"_rightclicked"
  global gVar_Click;
  gVar_Click = "R";
  sub "main";




HTH? :biggrin:

.

klownboy
Posts: 4424
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7462 at 100% 2560x1440

Re: Detect left vs right click on a CTB

Post by klownboy »

Hey Stefan, thanks for the reply. I used a very similar technique on another script. My problem is when I step throught the script it works up to displaying the message for whether I pressed "Left" or "Right" in my example below. So it performs an action or command (e.g., the message), but I can't get it to actually display a menu from sub main. When a menu item is selected (if it worked), an action would be performed and those actions would be different based on the global variable "$click". The menu works fine in a the normal situation calling it from a CTB but the menu does not appear when used here.
See a slimmed down example:

Code: Select all

 "_leftclicked";
  global $click;
  $click = "L";
  sub "Main";

"_rightclicked";
  global $click;
  $click = "R";
  sub "Main";

"Main";
  global $click;
    msg "you hit $click";  // this message does display so it works up to here!
"Pictures && Icons";
  global $click;
"All Maine Pics|D:\Graphics\Icons\k321-icon-218.ico" goto "G:\Pictures\Maine";
    sub _expand_it;
"Cascade Falls|:viewthumbs" goto "G:\Pictures\Cascade Falls";
    sub _expand_it;
     // bla, bla, bla, on and on...
"-"
"Wallpaper"
"All Wallpaper|D:\Graphics\Icons\wallpaper.ico" goto "g:\Wallpaper\1920x1080";
    sub _expand_it;
"England|D:\Graphics\Icons\Picture.ico" goto "G:\Wallpaper\1920x1080\England";
    sub _expand_it;
   // bla, bla, bla, on and on...
Any ideas what I may be doing wrong or if it may not be possible? By the way, you didn't mean separate leftClick.xys and rightClick.xys scripts in your example, did you? I assume you meant the assignments for on click and on right click in the CTB...obviously I wanted to do this in one script that was the whole point.
Thanks so much,
Ken

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Detect left vs right click on a CTB

Post by Stefan »

Yes, i thought about three separate scripts (mostly for better clarifying), but your are absolutely right, one script is enough.


But you will not see an menu after executing the script once with one of the hidden sub menus.

Therefor we will just load the script again after setting the value of the "$click" variable first.
To do this we get the current name and path of this script and then load it again:


CTB
. . . . On click: load "<xyscripts>\temp\a-01", "_leftclicked";
On right-click: load "<xyscripts>\temp\a-01", "_rightclicked";


a-01.xys

Code: Select all

"_leftclicked";
  global $click;
  $click = "L";
  msg "left";
  //sub "Main";
  self $ScriptFile, file; load $ScriptFile;  // <<<< I've modified your script by just adding this line 

"_rightclicked";
  global $click;
  $click = "R";
  msg "right";
  //sub "Main";
  self $ScriptFile, file; load $ScriptFile;


"Main";
  global $click;
    msg "you hit $click";  // this message does display so it works up to here!
    
"Pictures && Icons";
  global $click;
  msg "you hit $click";  
  
"All Maine Pics|D:\Graphics\Icons\k321-icon-218.ico" goto "G:\Pictures\Maine";
    sub _expand_it;
    msg "you hit $click";  
    
"Cascade Falls|:viewthumbs" goto "G:\Pictures\Cascade Falls";
    sub _expand_it;
     // bla, bla, bla, on and on...
"-"
"Wallpaper"
"All Wallpaper|D:\Graphics\Icons\wallpaper.ico" goto "g:\Wallpaper\1920x1080";
    sub _expand_it;
"England|D:\Graphics\Icons\Picture.ico" goto "G:\Wallpaper\1920x1080\England";
    sub _expand_it;
   // bla, bla, bla, on and on..


Explanation:

"_leftclicked";

global $click; //make the variable global to that script.
I thought i had to use "perm" to have it still in memory for the second script call, but this was not needed.

$click = "L"; //set the variable

msg "left"; //debugging feedback

//sub "Main"; // wrong way in this case

self $ScriptFile, file; load $ScriptFile; //get current script name and call it again

Of course just reuse the script name here as load "<xyscripts>\temp\a-01"; would work too.
But self $ScriptFile, file; load $ScriptFile; is more flexible if you rename the script.



I hope this approach works better.

.

klownboy
Posts: 4424
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7462 at 100% 2560x1440

Re: Detect left vs right click on a CTB

Post by klownboy »

Hi Stefan,
I used your suggestion of "load self(file)" in lieu of using "sub" and the results were great with one exception. For the "right" click, I receive the following screen and have to click on the "_rightclicked" menu item to get the actual "right click" menu I want to see. Edit: I meant to say also, when stepping through the script, this menu comes up in the very first step after right clicking.
SNIP.JPG
SNIP.JPG (13.99 KiB) Viewed 3307 times
Obviously, the right click menu would display properly when using 2 separate scripts - one for left, one for right click. The normal or left click menu displays immediately when I left click as it should. Do you have any idea what I might be able to do to bypass that intermediate menu (the one shown above) and have the script immediately display the right click menu or should I say the right click menu I want to display. If we can't get around this issue, I'm afraid I'd might as well go back to 2 separate scripts unfortunately. By the way, this is what I would want to see if I right clicked - results using 2 separate scripts. It's a nice technique though and one that I'd use in other ways if we can get beyond this issue. The options based on the "$click" variable worked great.
Thanks so much,
Ken
Attachments
rigthClick_capture.JPG
rigthClick_capture.JPG (31.61 KiB) Viewed 3307 times

klownboy
Posts: 4424
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7462 at 100% 2560x1440

Re: Detect left vs right click on a CTB

Post by klownboy »

Hey again Stefan,
I think I found an answer to my previous post. The script now does what I need it to do (i.e., uses only one script and does something different using left click vs a right click). It's certainly not a complete fix nor is it what I was initially hoping to do.

As I stated above, it was only the "right click" option that led to a the intermediate menu that I showed above. No matter what I tried, I couldn't get the right click menu do come up directly.
So in the CTB I used the following:
On click: load "D:\Tools\Xyplorer\Scripts\ThumbnailViewer_exec.xys", "_leftclicked";
On right-click: load "D:\Tools\Xyplorer\Scripts\ThumbnailViewer_exec.xys";

In the first part of the script I did the following:

Code: Select all

// beginning of script

"_leftclicked : _leftclicked";
  global $click;
  $click = "L";
       // msg "you hit $click";
       load self(file);

"Pictures && Icons";
"All Ireland Pics|D:\Graphics\Icons\k321-icon-218.ico" goto "G:\Pictures\Ireland Trip 2011";
    sub _expand_it;
"Cascade Falls|:viewthumbs" goto "G:\Pictures\Cascade Falls";
    sub _expand_it;
// and so on
The "right click" simply executes the script ignoring the hidden label, and the "left click" executes the hidden label, sets the variable to "L", and loads the script. Both options result in the identical menu displaying but result in different actions due to the variable.
Variable $click "L" is used to determine the action path taken. The way I figure it, you only have 2 choices, "Left click" or "Right click". So if it's not a left click, it has to be a right click. So further in the script:

Code: Select all

"_expand_it";
  global $click;
  
      if get(#660) {#660;}    // Address Bar
      if($click == "L") {     // Toolbar
        if get(#661) {#661}
        }
      if($click != "L") {
        if !get(#661) {#661}
        }
      if get(#662) {#662;}    // Tab bar
      if get(#663) {#663;}    // Nav Pnl
      if get(#665) {#665;}    // Info Pnl
      if get(#670) {#670;}    // Status Bar
      if get(#1061) {#1061;}  // Menu Bar
      if get("#800") {#800;}  // Dual Pane
If you figure out a better or smarter way please let me know. Thanks for all your help Stefan,
Ken

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Detect left vs right click on a CTB

Post by Stefan »

Hi Ken, sorry, have not much time.
klownboy wrote:As I stated above, it was only the "right click" option that led to a the intermediate menu
that I showed above. No matter what I tried, I couldn't get the right click menu do come up directly.
I think that is indented because you have to access the button context menu too, somehow.


I don't have tested what is possible right now (and forgot my last experiences)
but maybe we can ask Don for an workaround like opening the context menu
by holding the shift key while right clicking only, and right click alone immediately execute the script,
but that would be to hidden for new users.
Any ideas for an new wish thread about that issue?

klownboy
Posts: 4424
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7462 at 100% 2560x1440

Re: Detect left vs right click on a CTB

Post by klownboy »

Hey Stefan, I agree totally. It would be nice to have a built-in way in scripting to determine if you Left clicked or Right clicked a CTB. It's funny you asked what you did, because in this post http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=8231 awhile back I asked Don if it would be possible to not have the Click, Edit..., and Customize toolbar... menu items display when you "right clicked". In other words, have a tweak or code change to disable seeing those items when you "right clicked". You can easily assess those menu items by holding down the control key with a right click anyway. Yes, it's just aesthetics but why not.

So what we are asking (i.e., to have the right click immediately open a menu when loaded via a script label and somehow recognizing when a right click is used vs a left click) actually goes hand in hand with what I asked above. Unlike you, I'm far from being an expert at scripting, is that essentially what we would like?

Thanks again,
Ken

Post Reply