ScriptSpot

Forum topic · General Scripting

keyboard button to rollout button

By zahid hasan · 2020-05-27

Description

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 (8)

.

jahman · 2020-05-27

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.

zahid hasan · 2020-05-28

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.

zahid hasan · 2020-05-28

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

.

jahman · 2020-05-28

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

zahid hasan · 2020-05-28

Thank You. Will try it tonight. :-)

zahid hasan · 2020-05-28

It is working perfectly. Thanks a lot.

.

miauu · 2020-05-27

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"
		)
	)
)

zahid hasan · 2020-05-28

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