keyboard button to rollout button

Hi, I have a rollout with a few button which i want to link to any keyboard key for easy access. even shift or alt key will do. I am not sure how to link the rollout button with key.

on keyboard.shiftPressed() do
(btnnext.pressed())

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jahman's picture

.

If you want to keep it simple then use a timer and check for any key combination on tick event

(
 
	isKeyDown = (dotNetClass "managedservices.keyboard").isKeyDown
	keys = dotNetClass "system.windows.forms.keys"
 
	show keys
 
	while not keyboard.escPressed do
	(
		sleep 0.05
 
		if isKeyDown keys.Space and isKeyDown keys.ControlKey do 
		(
			format "Ctrl + Spacebar is pressed\n" 
		)	
 
	)        
 
)

Using macros for such task is an overkill, imho.

zahidhasan's picture

It is freezing max. I used it

It is freezing max. I used it both in and out of Rollout body.
Am i doing it wrong?

jahman's picture

.

of course it freezes max, it's just an example of the idea ;)

Use a timer control in your rollout and do these key-combination checks inside its tick event.

another example:

try(DestroyDialog ::test)catch()
rollout test "Detect Key Press" width:214
(
	timer clock "testClock" interval:100 -- 10 times a second
 
	local isKeyDown = (dotNetClass "managedservices.keyboard").isKeyDown
	local keys = dotNetClass "system.windows.forms.keys"
 
	CheckButton ctrl "Ctrl" width:40 pos:[4,4] across:4
	CheckButton shift "Shift" width:40 pos:[46,4]
	CheckButton alt "Alt" width:40 pos:[88,4]
	CheckButton space "Spacebar" width:80 pos:[130,4]
 
 
	fn CheckKeys = 
	(		
		-- for alt, ctrl, shift & esc we can use these		
		if alt.checked != keyboard.altPressed do alt.checked = keyboard.altPressed
		if ctrl.checked != keyboard.controlPressed do ctrl.checked = keyboard.controlPressed
		if shift.checked != keyboard.shiftPressed do shift.checked = keyboard.shiftPressed
 
		-- for any other keys
		local space_down = isKeyDown keys.Space
 
		if space.checked != space_down do space.checked = space_down
 
	)
	on clock tick do
	(
		CheckKeys()		
		format "tick...\n"
	)
)
createDialog test
zahidhasan's picture

Thank You. Will try it

Thank You. Will try it tonight. :-)

zahidhasan's picture

It is working perfectly.

It is working perfectly. Thanks a lot.

zahidhasan's picture

Thank you. I shall try to

Thank you.
I shall try to implement it, and let you know.
Its very basic dotnet, still i shall need a bit time to understand it properly and tweak.
Really appreciate your quick replies.

miauu's picture

.

Create a macorscripts to press the keys on your toolbar.
For example:

macroscript myMacro_btnnext
category:"mycategory"
tooltip:"TOOLTIP NEEDED"
buttonText:"TEXT NEEDED"
 
(
	on execute do
	(
		if myRollout.open then
		(
			btnnext.pressed()
		)
		else
		(
			--	"run something else"
		)
	)
)
 
macroscript myMacro_btnPrev
category:"mycategory"
tooltip:"TOOLTIP NEEDED"
buttonText:"TEXT NEEDED"
 
(
	on execute do
	(
		if myRollout.open then
		(
			myMacro_btnPrev.pressed()
		)
		else
		(
			--	"run something else"
		)
	)
)
zahidhasan's picture

Its a wonderful solution.

Its a wonderful solution. Thank you Miauu.
All i have to do is assign hotkeys to that macro.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.