cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

ThomasZatValcon
Level III

Is there a way to check if a modifier key such as ctrl, alt or shift is depressed during execution of a jsl script? I know the "is ... key()" functions, but they only work with the mouse. I would like to let a script do various things on execution depending on which modifier key is depressed while it is executed.

7 REPLIES 7
ih
Super User (Alumni) ih
Super User (Alumni)


Re: Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

You can use functions like `is control key()`, like this:

 

New Window("Modifier Key Check",
	vlb = V List Box(
		Mouse Box(
			Graph Box(),
			<<setClickEnable( 1 ),
			<< Set Click( 
				Function( {this, clickpt, event}, 
					
					if( event == "Pressed",
						if( is alt key(),
							txt = "pressed with alt",
							is control key(),
							txt = "pressed with control",
							is shift key(),
							txt = "pressed with shift",
							txt = "pressed"
						);
						
						New Window("Button Pressed", << Modal, text box( txt ) );
					)
				)
			)
		)
	)
);
ih
Super User (Alumni) ih
Super User (Alumni)


Re: Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

Sorry I just read your post again and I guess you wanted to do this when not using the mouse.  Can you give a description of when a user would press a modifier key that isn't related to a mouse click?  I am having a hard time picturing your use case.


Re: Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

You can search the Scripting Index for functions. There is a group of Utility functions that includes inquiries about modifier keys that are current pressed.

 

is alt.PNG

hogi
Level XII


Re: Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

Hm, when I use the Enter button on the numeric keypad or the play button in the Scripting Index, I get:
- 0, if CTRL is NO being pressed

- 2 if CTRL is being pressed

isCtrlKey_ScriptingIndex.mp4
Video Player is loading.
Current Time 0:00
Duration 0:08
Loaded: 0%
Stream Type LIVE
Remaining Time 0:08
 
1x
    • Chapters
    • descriptions off, selected
    • captions off, selected
    • en (Main), selected
    (view in My Videos)

     

    If I try the same via the play button in the toolbar, the result is always 0 
    (believe me that I pressed CTRL or try it on your own :).
    Is this the expected behavior?

     

    isCtrlKey_Toolbar.mp4
    Video Player is loading.
    Current Time 0:00
    Duration 0:08
    Loaded: 0%
    Stream Type LIVE
    Remaining Time 0:08
     
    1x
      • Chapters
      • descriptions off, selected
      • captions off, selected
      • en (Main), selected
      (view in My Videos)

       

      The idea was to trigger 2 different actions depending on the CTRL status.
      Is there another way to get the info about the CTRL status - maybe especially for a script that is triggered by clicking on an icon in a toolbar?

      hogi
      Level XII

      Re: Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

      Feedback from Jmp developer [TS-00139632]:

      This function does not return the current state of the control key but rather the state of the control key at the start of another event like mouse click or key press. JMP does have an internal function to get the modified key state at any time but this is not exposed via JSL. If you would like this added, I would suggest that you add it to the JMP Wish List.

      -> here is the wish:
      JSL function to get the current status of modifier keys

      This post originally written in German and has been translated for your convenience. When you reply, it will also be translated back to German.

      hogi
      Level XII


      Re: Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

      My application cases:

      1. send to PPT
        - default: send a screenshot to powerpoint
        - with CTRL pressed, send a vector graphics to powerpoint

      2.  subsets
        - default: create a linked subset
        - with CTRL : create a subset which is not linked
        - with Shift : just include columns which are selected at the moment.

       

      How will you use this new functionality?

      The wish got "acknowledged" - now it's up to the users to show interest ... 
      Please follow the link and support the wish with a Kudo : 
      JSL function to get the current status of modifier keys 

      hogi
      Level XII


      Re: Checking for modifier keys (ctrl, alt, shift) in script without mouse trapping

       

      is control Key ()could be so useful!

       

      Another application case:

      for(t=5, t>-1, t--,
      Caption("go to the plot\!n"|| Char(t));
      if(is control Key (), break());
       wait(1);
      );
      Caption(remove);

      I want to give the user the chance to stop the for loop manually - via a key on the keyboard.
      Interesting that one needs a mouse click to allow JMP to process the current state of a key.