Capture ctrl+click from button not in focus?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Capture ctrl+click from button not in focus?

Post by dan.potter »

Is it possible to do this?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Capture ctrl+click from button not in focus?

Post by jvierra »

Events are always handled. How could you create a click on a control not in focus. That is not possible. Keyboard and mouse events are always handled by the control in focus.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Capture ctrl+click from button not in focus?

Post by dan.potter »

I was hoping their was a simpler way within the click event.

Code: Select all

$Creds_Click={
	
	if ($ctrl) { Get-Credential | Export-Clixml $env:userprofile\cred.xml 
	
	$ctrl = $false
		
	}
	
}

$cred_keydown=[System.Windows.Forms.KeyEventHandler]{
	
	$script:ctrl = $true
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Capture ctrl+click from button not in focus?

Post by jvierra »

The click event is only called when you click the button. You can use Mouse down but that only works when the control has focus.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked