International keyboards
-
- User
- Posts: 84
- Joined: Mon Jun 30, 2008 4:36 pm
- Location: UK
International keyboards
Hi there,
Is it okay to assume that the caret symbol (^) is obtained by typing SHIFT+6 on any keyboard? And the plus character with SHIFT+=? In general, what assumptions can I make about obtaining ascii symbols that won’t break my code on a foreign keyboard?
Thank you.
Is it okay to assume that the caret symbol (^) is obtained by typing SHIFT+6 on any keyboard? And the plus character with SHIFT+=? In general, what assumptions can I make about obtaining ascii symbols that won’t break my code on a foreign keyboard?
Thank you.
Re: International keyboards
Some nordic countries place the ampersand on 6, instead of the carat.
It should still work, as long as it's not used for fast keys like a game; they place the carat on the far right, down a row.
It should still work, as long as it's not used for fast keys like a game; they place the carat on the far right, down a row.
Re: International keyboards
Generally, it's not good practice to determine key presses by keyboard layout. Input should be strictly ascertained by their ASCII codes.ProphetOfDoom wrote:...Is it okay to assume that the caret symbol (^) is obtained by typing SHIFT+6 on any keyboard?...
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

Re: International keyboards
No, it is not. With french keyboard:ProphetOfDoom wrote: Is it okay to assume that the caret symbol (^) is obtained by typing SHIFT+6 on any keyboard? And the plus character with SHIFT+=?
^ = Alt Gr + 9
+ = Maj + +
Like TI-994A said: it is preferable to use ascii codes.
But except for games and simulators where the position of the keys is preferable for ergonomics,
For keyboard layout by country, search for
keyboard layout by country
PS. If you knew how annoying our french keyboards are for system administrators

\ = Alt Gr + 8 (this is why we prefer linux console with / who is at bottom left)

@ = Alt Gr + 0
etc
Re: International keyboards
Even that could prove problematic. A simple example would be the long-standing issue of the WASD keys, which provide a left-handed ergonomic alternative to the arrow keys. On the popular DVORAK keyboards, the positions of the W, S and D keys vary from that on QWERTY keyboards, essentially rendering the option impractical.Marc56us wrote:...But except for games and simulators where the position of the keys is preferable for ergonomics...
For such mechanical purposes, a good practice would be to facilitate customised key mappings.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

-
- User
- Posts: 84
- Joined: Mon Jun 30, 2008 4:36 pm
- Location: UK
Re: International keyboards
Wow thanks for the quick replies.
This is what I feared.
Let me explain my use case...
I'm making a scientific calculator. I thought it would be cool to draw it on a WindowedScreen, with artwork to make it look like a real hardware calculator. But there doesn't seem to be a way to get ascii values for + * ^ operators when the user types them? KeyboardPushed() and the keyboard shortcuts API seem to be tied to scancodes and a very limited set of keys. Maybe I will be forced to just use the boring grey gadgets.
This is what I feared.
Let me explain my use case...
I'm making a scientific calculator. I thought it would be cool to draw it on a WindowedScreen, with artwork to make it look like a real hardware calculator. But there doesn't seem to be a way to get ascii values for + * ^ operators when the user types them? KeyboardPushed() and the keyboard shortcuts API seem to be tied to scancodes and a very limited set of keys. Maybe I will be forced to just use the boring grey gadgets.
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: International keyboards
...not at all, you can use the Unicode erm, code, for any character not found in ASCII. Just ensure that you have a good font such as "Arial Unicode MS" that contains the required characters. You can ship fonts with your software if necessary.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- User
- Posts: 84
- Joined: Mon Jun 30, 2008 4:36 pm
- Location: UK
Re: International keyboards
Sorry not understanding this IdeasVacuum.
Marc56us says his caret on his French keyboard is ALT-GR+9; on my English keyboard it’s SHIFT+6. So which PureBasic API function can report the caret character, rather than the keys the user pressed, which could mean either?
Marc56us says his caret on his French keyboard is ALT-GR+9; on my English keyboard it’s SHIFT+6. So which PureBasic API function can report the caret character, rather than the keys the user pressed, which could mean either?
Re: International keyboards
Here's one approach:ProphetOfDoom wrote:...making a scientific calculator. I thought it would be cool to draw it on a WindowedScreen, with artwork to make it look like a real hardware calculator. But there doesn't seem to be a way to get ascii values for + * ^ operators when the user types them?
Code: Select all
Enumeration
#MainWindow
#Canvas
#Sprite
#Arial
EndEnumeration
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If InitSprite() And
OpenWindow(#MainWindow, 0, 0, 300, 400, "Canvas Input", wFlags) And
OpenWindowedScreen(WindowID(#MainWindow), 10, 10, 280, 380)
LoadFont(#Arial, "Arial", 36, #PB_Font_Bold)
CanvasGadget(#Canvas, 290, 0, 10, 400, #PB_Canvas_Keyboard)
SetWindowColor(#MainWindow, #White)
SetActiveGadget(#Canvas)
ClearScreen(#Cyan)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Gadget
Select EventGadget()
Case #Canvas
Select EventType()
Case #PB_EventType_Input
ClearScreen(#Cyan)
input$ = Chr(GetGadgetAttribute(#Canvas, #PB_Canvas_Input))
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Arial))
DrawText(125, 125, input$, #Blue)
StopDrawing()
FlipBuffers()
EndIf
EndSelect
EndSelect
EndSelect
Until appQuit
EndIf
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel 

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: International keyboards
... I thought you meant your Calculator would have it's own keys. If the program has to use keyboard input, how about asking the User, on first use only, to identify the keys?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Enthusiast
- Posts: 581
- Joined: Wed Sep 25, 2019 10:18 am
Re: International keyboards
Hello ProphetOfDoom,
here is an example of an international keyboard, Gurmukhi for Panjabi:

here is an example of an international keyboard, Gurmukhi for Panjabi:

Please ask your questions, because switch on the cognition apparatus decides on the only known life in the universe.Wersten :DDüsseldorf NRW Germany Europe Earth Solar System Flake Bubble Orionarm
Milky Way Local_Group Virgo Supercluster Laniakea Universe
Milky Way Local_Group Virgo Supercluster Laniakea Universe
Re: International keyboards
This is for Windows only and should report a Shift+Caret keypress for any keyboard. Could some people test and let me know? Thanks!ProphetOfDoom wrote:which PureBasic API function can report the caret character, rather than the keys the user pressed
Code: Select all
; This structure maybe not needed?
; Structure KeyboardState
; b.b[256]
; EndStructure
; kbs.KeyboardState
key.w=VkKeyScanEx_(Asc("^"),GetKeyboardLayout_(0))
k$=Space(9)
ToAscii_(key,MapVirtualKey_(key,#MAPVK_VK_TO_CHAR),@kbs,@k$,0)
VK_CARET=Asc(Trim(k$))
Macro KeyIsDown(key)
GetAsyncKeyState_(key) & $8000
EndMacro
Macro KeyIsUp(key)
GetAsyncKeyState_(key)=0
EndMacro
Debug "Press the Caret key..."
Repeat
Sleep_(1)
If KeyIsDown(#VK_SHIFT) And KeyIsDown(VK_CARET) ; Shift+Caret key down.
Debug "Caret pressed"
Repeat : Sleep_(1) : Until KeyIsUp(VK_CARET) ; Wait for Caret key up.
EndIf
ForEver
Re: International keyboards
Doesn't work here, with german keyboard. Additionally the ^ character is entered here on a german keyboard without shift.
Debug show, that:
Debug show, that:
key = 220
VK_CARET = 94
k$ = ^
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: International keyboards
Why not simply use something like the example in the KeyboardInkey() help
With: If FindString("^", result$)
With: If FindString("^", result$)
Re: International keyboards
I'm not sure if it is a bug, but here on german windows 10, PB 5.72 the result of KeyboardInkey() is "幞" when I press the [^]-key.
In this case FindString("^", result$) wouldn't work
Since the hex number is 5E5E it seems like, it is just doubled, because 5E is the ^ character.
In this case FindString("^", result$) wouldn't work

Code: Select all
Enumeration
#Window
EndEnumeration
InitSprite()
InitKeyboard()
OpenWindow(#Window, 100, 100, 800, 450, "KeyboardInkey", #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(#Window), 0, 0, 800, 450)
Define String.s
Repeat
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
Break 2
Case #PB_Event_None
Break
EndSelect
ForEver
ExamineKeyboard()
String = KeyboardInkey()
If String
Debug String + " (0x"+Hex(Asc(String))+")"
EndIf
ClearScreen($000000)
FlipBuffers()
ForEver
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module