Use the "ESC" key

Post

Posted
Rating:
#1 (In Topic #1121)
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Hi, everyone.

I have the following problem:

I created a "Back" button and use Alt+V to make it work with the keyboard.

My ideal would be "Back" or "Go Back" or "Abort" with the "ESC" key but I don't know how to do it directly for the same button.

What I want to do is use the "ESC" key to execute a Reparent type command or call a subroutine and return window control to the previous state.

Can anyone suggest me how to do it, if possible?

Thank you

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

Code (gambas)

  1.  
  2. Public Sub Form_KeyPress()
  3.  
  4.   Select Key.Code
  5.    Case Key.Esc
  6.    ' your code here
  7.  
  8.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 I knew about this option but it is not good to use it. I need to associate it with a button. maybe it's not possible?

thank you

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
 so how are you using Alt+V as the shortcut for a button?

maybe make a menu item that does the same function and set the shortcut in the menu editor?
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Thank you
How do I do it? Would you be so kind as to give me an example?

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’

gambafeliz said

Thank you
How do I do it? Would you be so kind as to give me an example?

What show how to make a menu item in the IDE?
er, hit the "Menu editor" button ;)
Online now: No Back to the top

Post

Posted
Rating:
#7
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Okay, sorry, I thought it was about something else.

Thanks for everything.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Guru
cogier is in the usergroup ‘Guru’
If I read this correctly, you need to look at the Button properties of Default and Cancel. To get a Button to respond to a key press add a '&' before a letter in the Text property. In the example below [Alt]+O, [Alt]+C, [Esc] and [Return] will all 'Press' a Button.

Run the following code in a new graphical project: -

Code (gambas)

  1. ' Gambas class file
  2.  
  3. hBox1 As HBox
  4. ButtonOK As Button
  5. ButtonCancel As Button
  6. Spring1 As Spring
  7. LabelInfo As Label
  8. LabelMessage As Label
  9. Timer1 As Timer
  10.  
  11. Public Sub ButtonOK_Click()
  12.  
  13.   LabelMessage.Text = "OK pressed"
  14.   Timer1.Start
  15.  
  16.  
  17. Public Sub ButtonCancel_Click()
  18.  
  19.   LabelMessage.Text = "Cancel pressed"
  20.   Timer1.Start
  21.  
  22.  
  23. Public Sub Form_Open()
  24.  
  25.   With Me
  26.     .height = 200
  27.     .Width = 350
  28.     .Padding = 5
  29.     .Arrangement = Arrange.Vertical
  30.  
  31.   hPanel.Height = 10
  32.  
  33.   With LabelInfo = New Label(Me)
  34.     .Height = 28
  35.     .Alignment = Align.Center
  36.     .Font.Bold = True
  37.     .Font.Size = 14
  38.     .Text = "Press 'Esc' or 'Enter' or click a button"
  39.  
  40.   hPanel.Height = 10
  41.  
  42.   With hBox1 = New HBox(Me)
  43.     .Padding = 10
  44.     .Height = 50
  45.     .Width = 50
  46.  
  47.   With ButtonOK = New Button(hBox1) As "ButtonOK"
  48.     .Width = 112
  49.     .Height = 28
  50.     .Default = True          ''Here is the property you need
  51.     .Text = "&OK"
  52.  
  53.   Spring1 = New Spring(hBox1)
  54.  
  55.   With ButtonCancel = New Button(hBox1) As "ButtonCancel"
  56.     .Width = 112
  57.     .Height = 28
  58.     .Cancel = True           ''Here is the property you need
  59.     .Text = "&Cancel"
  60.  
  61.   hPanel.Height = 50
  62.  
  63.   With LabelMessage = New Label(Me) As "LabelMessage"
  64.     .Height = 28
  65.     .Width = 100
  66.     .Alignment = Align.Center
  67.     .Font.Bold = True
  68.     .Font.Size = 14
  69.  
  70.   Timer1 = New Timer As "Timer1"
  71.   Timer1.Delay = 2000
  72.  
  73.  
  74. Public Sub Timer1_Timer()
  75.  
  76.   LabelMessage.Text = ""
  77.   Timer1.Stop
  78.  
  79.  
Online now: No Back to the top

Post

Posted
Rating:
#9
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
You have left me impressed. Yes, that's what I'm looking for. Thank you.

But I promise you that I don't understand the mechanism to get a button to be pressed with "ESC" from the keyboard, even by reading your code. I'm even like the Indians in the tribes, when they say it's magic and I go to the corner afraid of what you've done. :)

Note: I would love some technical explanation about the mechanism, but, I'll leave it to you if you want.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#10
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Ok

Property:
.Cancel = True (ESC)

Thank you

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#11
Guru
BruceSteers is in the usergroup ‘Guru’

gambafeliz said

Ok

Property:
.Cancel = True (ESC)

Thank you

Indeed and in the same respect.
Property:
.Default = True (Return/Enter)

I hadn't thought of that.
That's actually a cool tip and something to think of in my applications to quickly set return or escape to a button  <EMOJI seq="1f60e" tseq="1f60e">😎</EMOJI>
Cheers Charlie  <EMOJI seq="1f60a" tseq="1f60a">😊</EMOJI>
Online now: No Back to the top

Post

Posted
Rating:
#12
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
I absolutely agree, excellent recommendation. Now my program will be much more intuitive in using the keyboard. Thank you.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.