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.
Locked
User avatar
dan.potter
Posts: 709
Joined: Wed Oct 08, 2014 6:02 am

Capture ctrl+click from button not in focus?

Post by dan.potter » Tue Nov 21, 2017 8:59 am

Is it possible to do this?

User avatar
jvierra
Posts: 13480
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Tue Nov 21, 2017 9:38 am

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
Joined: Wed Oct 08, 2014 6:02 am

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

Post by dan.potter » Thu Nov 23, 2017 5:00 am

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
}

User avatar
jvierra
Posts: 13480
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu Nov 23, 2017 5:13 am

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.

Locked