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 8 years and 8 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.
for my newest project I have some minor issue where I hope I get some help from you out there.
I have a PowerShell forms script with a menue.
This menue contains a hidden menue which should be visible after hitting a hotkey like ALT+D (just an example)
(don´t blame me this is just a kind of pseudo-code )
I´ve tried to use the Keydown event from my $mainform object but had no luck. this event is never triggered.
Any ideas?
This is an automated post. A real person will respond soon.
Thank you for posting, Luke_F.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
- Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
If you asked in the wrong forum, just copy your question to the right forum.
Anticipate follow-up questions!
Did you remember to include the following?
1. Product, version and build
2. 32 or 64 bit product
3. Operating system, e.g. Windows 7 64 bit.
4. Attach a screenshot, if applicable
5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.
*** Make sure you do not post any licensing information ***
for my newest project I have some minor issue where I hope I get some help from you out there.
I have a PowerShell forms script with a menue.
This menue contains a hidden menue which should be visible after hitting a hotkey like ALT+D (just an example)
(don´t blame me this is just a kind of pseudo-code )
I´ve tried to use the Keydown event from my $mainform object but had no luck. this event is never triggered.
Any ideas?
Thanks to you all in advance
PowerShell Code
Double-click the code block to select all.
$textbox1_KeyDown=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
#TODO: Place custom script here
if ($_.alt -and $_.KeyCode -eq 'D') { Write-Host 'alt + D was pressed' }
}
Thanks for your quick response.
I may have to ask my question more precicely.
The issue I have is not about "how to identify which button is pressed" but how to define the event for it.
From your examtle the $textbox1 must be the active element to get the keys. But I need to have this working independendly on the focused item.
TO capture keystrokes we need to set the forms "KeyPreview" property to $true and define the keyhander on the form. This is known as a "global" keystroke handler.
PowerShell Code
Double-click the code block to select all.
$form1_KeyDown=[System.Windows.Forms.KeyEventHandler]{
if ($_.alt -and $_.KeyCode -eq 'D') {
Write-Host 'alt + D was pressed'
$_.SuppressKeyPress=$true
}
}
This topic is 8 years and 8 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.