Key["ENTER"] code fails in my PC. Why ?
Posted
#1
(In Topic #1276)
Regular

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
Posted
Guru

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.
Posted
Regular

<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
Posted
Regular

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
Posted
Guru

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.
Posted
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)
Posted
Guru

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….
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
1 guest and 0 members have just viewed this.


