Key["ENTER"] code fails in my PC. Why ?

Post

Posted
Rating:
#1 (In Topic #1276)
Regular
sergioabreu is in the usergroup ‘Regular’
 The Key["ENTER"] fails in my PC.

Gambas has hardcoded ENTER to 16777221 and my machine generates 16777220 instead
I tested the ENTER key from numeric pad and it has a "10" as code.

I wonder why gambas invented total different keycodes compared to java/javascript… that always worked and Visual Basic used too (keycode 13)

We need to handle two different key codes to handle the textpad Enter and numeric pad Enter as they produce different codes…

How would veterans do to use a global ENTER key using gambas ? I decide to do this:

In the top of the .class file I declare:
   
    Public Enters as Variant = [10, 16777221, 16777220 ]

Then in the code I can do:

    If Enters.find( Key.Code) > -1 Then
          'gets trapped with all key codes and worked
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
I would use the constants

Code (gambas)

  1. If Key.Code = Key.Enter Or If Key.Code = Key.Return Then
  2.   Print "Enter"
  3.  

And Gambas hasn't hardcoded anything.

gambas uses the GUI toolkits either GTK or QT , it's the toolkits that define what value Key.Enter or Key["Enter"] is
you will find the value is different on GTK than it is on QT

the Gambas wiki warns not to use the integer values you see as key codes as they differ for each toolkit.

Note. the numbpad enter is the actual Key.Enter the one up on the keyboard is Key.Return  and I am glad they do not fire the same code , they are different keys.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
sergioabreu is in the usergroup ‘Regular’
The Gambas wiki diplays this for the Key.Enter page:

<COLOR color="#0000FF">Const Enter As Integer = 16777221 ' &H1000005 </COLOR>

Can't we name  it "hardcoded" ?

If someone says "PRESS ENTER" which key 99.9% of the people will press?

Thanks for explaining the differce between Return and Enter, I didn't know, even the Keyboard calls  both as "Enter".

You are right. When I say Gambas, I refer to the whole software. If it uses GTK and QT It doesn't matter for the user.

IMHO the key["ENTER"] could work for both… NOBODY calls the Central "Enter" key as return

In javascript both keys generate the same keyCode = 13
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
sergioabreu is in the usergroup ‘Regular’
With all new information, here is my approach to save "typing"

Code

Public Function isEnter(code As Integer) As Boolean
  Return (code = Key.enter Or code = Key.return)
End

     If isEnter(key.code) then ...
         ... do stuff
     Endif

Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
13 isn't a key code it's an ascii value for CR

GTK3  Key.Enter = 65421
QT5    Key.Enter = 16777221

the gambas wiki page you are looking at is /comp/gb.qt4/key/enter - Gambas Documentation
  (the keyword in that URL being qt4 , so it's qt toolkit specific)

It's not hard coded , it's specific according to the toolkit.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
sergioabreu is in the usergroup ‘Regular’

BruceSteers said

13 isn't a key code it's an ascii value for CR

GTK3  Key.Enter = 65421
QT5    Key.Enter = 16777221

the gambas wiki page you are looking at is /comp/gb.qt4/key/enter - Gambas Documentation
  (the keyword being qt4 , so it's qt specific)

It's not hard coded , it's specific according to the toolkit.

Javascript calls it keyCode

(Event.keyCode == 13)
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
Gambas is how it is.

Key["Return"] is what it is.
Key["Enter"] is what it is.

to be blunt your opinion as to how you think it should be ,,, kinda matters not.

It's gambas ,   it's not javascript , it's not visual basic , it's gambas.  
how it works in javascript doesn't matter, how it works in VB doesn't matter.

Gambas has been around for years and many people have software so even if you are convinced something should work differently the chances are it never will as this will break other peoples code.

so you'll just have to get your head around the gambas way of doing things even if JS and VB do it different.
With gambas there are often many roads to Rome ;)

Here is an alternative method that looks more like the JS you want it to with ascii value 13….

Code (gambas)

  1. If Key.Text = Chr(13) Then
  2.   ' do stuff
  3.  

But is it the best way of doing it?  i do not think so, i would use the gambas constants Key.Enter or Key.Return , Using Chr(iAsciiValue) will work for keys that have text but not for modifier keys (Ctrl/Shift/etc) and F keys
Online now: No Back to the top
1 guest and 0 members have just viewed this.