Hello,
I'm not sure how to word this to find a result on google, but essentially I'd like to enter in '↑↑↓↓←→←→BA' to open a child form
Any chance of how this can be done?
To be clear, I want to press:
up arrow
up arrow
down arrow
down arrow
left arrow
right arrow
left arrow
right arrow
B
A
multiple keystrokes to open child form
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.
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.
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am
Re: multiple keystrokes to open child form
Yes, you can accomplish this by using an array that keeps track of the sequence of keys. In the form's KeyDown event, check if the KeyCode matches:
You will also have to set the form's KeyPreview property to True.
Code: Select all
$script:KeyPressSequence = @('Up', 'Down', 'Up', 'Down', 'Left', 'Right', 'Left', 'Right', 'A', 'B', 'A', 'B')
$script:KeySequenceIndex = 0
$form1_KeyDown=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
#TODO: Place custom script here
Write-Host $_.KeyCode
if ($_.KeyCode -eq $script:KeyPressSequence[$script:KeySequenceIndex])
{
#increment the sequence
$script:KeySequenceIndex++
#Did we finish the sequence?
if ($script:KeySequenceIndex -ge $script:KeyPressSequence.Length)
{
$script:KeySequenceIndex = 0; #Reset counter
#Show the Form here
Write-Host 'Show the child Form'
}
}
}
Code: Select all
$form1.KeyPreview = $True
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- apowershelluser
- Posts: 194
- Last visit: Fri Mar 22, 2024 4:38 am