How do I call a button click by pressing the Enter key in Powershell

sloppyfrenzy

I have a drop down list that's populated by a CSV file. Next to the list is a 'Go' button that puts the CSV info into the rest of the program based on what's chosen. When a value is selected I'd like to be able to press Enter instead of clicking Go and have the Enter key basically call the button click. Am I thinking of that correctly? I've found a few things, but none of them have seemed to work. Probably because I don't know where to put it in my code.

Here's the drop down menu and button code...

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 120
$System_Drawing_Size.Height = 20
$label5.Size = $System_Drawing_Size
$label5.Text = "Company Presets:"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 223
$System_Drawing_Point.Y = 18 #545
$label5.Location = $System_Drawing_Point
$label5.DataBindings.DefaultDataSourceUpdateMode = 0
$label5.Name = "label5"
$label5.BackColor = "Transparent"

$form1.Controls.Add($label5)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 225
$System_Drawing_Point.Y = 46 #569
$companybox.Location = $System_Drawing_Point
$companybox.DataBindings.DefaultDataSourceUpdateMode = 0
$companybox.FormattingEnabled = $True
$companybox.Name = "companybox"
$companybox.TabIndex = 18
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 30
$System_Drawing_Size.Width = 260
$companybox.Size = $System_Drawing_Size
$companybox.DropDownHeight = 125

ForEach ($Items in $List) {

    $companybox.Items.Add($Items)

}

$companybox.AutoCompleteSource = 'CustomSource'
$companybox.AutoCompleteMode='SuggestAppend'
$companybox.AutoCompleteCustomSource=$autocomplete
$List | % {$companybox.AutoCompleteCustomSource.AddRange($_) }

$Form1.Controls.Add($companybox)

$gobutton.TabIndex = 20
$gobutton.Name = "Go"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 34
$System_Drawing_Size.Height = 23
$gobutton.Size = $System_Drawing_Size
$gobutton.UseVisualStyleBackColor = $True
$gobutton.Text = "Go"
$gobutton.ForeColor = "Black"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 490
$System_Drawing_Point.Y = 44 #567
$gobutton.Location = $System_Drawing_Point
$gobutton.DataBindings.DefaultDataSourceUpdateMode = 0
$gobutton.add_Click($handler_gobutton_Click)

$form1.Controls.Add($gobutton)

Here are three things I've tried. I've put these chunks in the $companybox section, and the $gobutton section, neither seems to work. I've changed the $textbox variable each time, tried changing the &$buttongo_click to $handler_gobutton_click, and $gobutton_click.

$textboxpath_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{ 
if ($_.KeyChar -eq [System.Windows.Forms.Keys]::Enter) { 
&$buttonGo_Click 
} 
}

$textbox1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
if($_.KeyChar -eq 13){
    [void][System.Windows.Forms.MessageBox]::Show('Enter key entered'+$_.KeyChar)
}
}

$textbox1_KeyUp=[System.Windows.Forms.KeyEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyEventArgs]
if($_.KeyCode -eq 'Enter')
{
    &$button1_Click
}
}

Thanks!

Keith Hill

Set the Form's AcceptButton property to the Go button e.g.:

$form1.AcceptButton = $goButton

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I call a button click by pressing the Enter key in Powershell

From Dev

Jquery: how to trigger click event on pressing enter key or clicking button

From Dev

How to trigger button click event on pressing enter button in c#

From Dev

How to trigger button click event on pressing enter button in c#

From Java

Jquery: how to trigger click event on pressing enter key

From Dev

How to trigger click event when pressing enter key? Text area

From Dev

WPF Pressing Enter Key How to Make Button look pressed

From Dev

How do I make it so pressing Enter in a textbox does the same as clicking the button next to it?

From Dev

how to emulate pressing the Enter key

From Dev

Pressing enter in text box to trigger click on a button

From Dev

Calling a click function when pressing the Enter key

From Dev

How do I check if the user is pressing a key?

From Java

to call onChange event after pressing Enter key

From Dev

Qualtrics: Pressing enter key to emulate continue button

From Dev

how do i trigger a button with the enter key in java script?/ how to give text box and search button an ID?

From Dev

Stopping enter key to click button

From Dev

Enter key is not working on button click

From Dev

GWT: On pressing KEY_ENTER I want to enable button's onclick method

From Dev

How do I click Enter using Splinter?

From Dev

How do I stop a button from triggering when the enter key is pressed? (focused)

From Dev

In java how do I check if a user is pressing a certain key?

From Dev

How do I call my NoteMain class when I click on the "Notes" Button in my android app

From Dev

After typing a URL in Google Chrome, how can I launch the address without pressing the Return/Enter key?

From Dev

Allow button click function on the Enter Key in Textbox

From Dev

How do I prevent any button click events from queuing until the event handle is finished with the first call

From Dev

How to submit form with enter key when I have a button, not a submit

From Dev

How to submit form with enter key when I have a button, not a submit

From Dev

MaterialDesignInXamlToolkit Dialog Boxes do not closed by pressing the ENTER key

From Dev

How can I make a winform button "do something" as long as I am pressing the button?

Related Related

  1. 1

    How do I call a button click by pressing the Enter key in Powershell

  2. 2

    Jquery: how to trigger click event on pressing enter key or clicking button

  3. 3

    How to trigger button click event on pressing enter button in c#

  4. 4

    How to trigger button click event on pressing enter button in c#

  5. 5

    Jquery: how to trigger click event on pressing enter key

  6. 6

    How to trigger click event when pressing enter key? Text area

  7. 7

    WPF Pressing Enter Key How to Make Button look pressed

  8. 8

    How do I make it so pressing Enter in a textbox does the same as clicking the button next to it?

  9. 9

    how to emulate pressing the Enter key

  10. 10

    Pressing enter in text box to trigger click on a button

  11. 11

    Calling a click function when pressing the Enter key

  12. 12

    How do I check if the user is pressing a key?

  13. 13

    to call onChange event after pressing Enter key

  14. 14

    Qualtrics: Pressing enter key to emulate continue button

  15. 15

    how do i trigger a button with the enter key in java script?/ how to give text box and search button an ID?

  16. 16

    Stopping enter key to click button

  17. 17

    Enter key is not working on button click

  18. 18

    GWT: On pressing KEY_ENTER I want to enable button's onclick method

  19. 19

    How do I click Enter using Splinter?

  20. 20

    How do I stop a button from triggering when the enter key is pressed? (focused)

  21. 21

    In java how do I check if a user is pressing a certain key?

  22. 22

    How do I call my NoteMain class when I click on the "Notes" Button in my android app

  23. 23

    After typing a URL in Google Chrome, how can I launch the address without pressing the Return/Enter key?

  24. 24

    Allow button click function on the Enter Key in Textbox

  25. 25

    How do I prevent any button click events from queuing until the event handle is finished with the first call

  26. 26

    How to submit form with enter key when I have a button, not a submit

  27. 27

    How to submit form with enter key when I have a button, not a submit

  28. 28

    MaterialDesignInXamlToolkit Dialog Boxes do not closed by pressing the ENTER key

  29. 29

    How can I make a winform button "do something" as long as I am pressing the button?

HotTag

Archive