cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
ThomasZatValcon
Level III

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

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.

5 REPLIES 5
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 XI

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

 

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?

 

 

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 XI

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