Problem with Virtual Keys

Just starting out? Need help? Post your questions and find answers here.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Problem with Virtual Keys

Post by charvista »

I am writing a kind of text editor, so I need to be able to capture every keystroke.
Some keys seem not to have a virtual key, like the comma (,) semicolon(:) or dot(.) (and some more).
So, how can I know when the user presses the comma key?
A standard way that will load the value 1036 in the Home key:

Code: Select all

AddKeyboardShortcut(Win,#PB_Shortcut_Home,1036)
In the event loop, it is then captured:

Code: Select all

  Repeat
    Event=WaitWindowEvent()
    Select Event
        Case #PB_Event_Menu
            KeyCode=EventMenu()
            If KeyCode=1036
etc......
Thanks in advance
Cheers
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Problem with Virtual Keys

Post by LuCiFeR[SD] »

#VK_OEM_PERIOD (Full stop/Period or dot as you call it)
#VK_OEM_COMMA (Comma)
#VK_OEM_1 (For colon and semicolon ";:") <<<== US Keyboards?

MSDN is your friend
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Problem with Virtual Keys

Post by charvista »

Thank you so much Lucifer, together with MSDN you are also a good friend :D
I could remap all of the important keys, except one. That's the "<>\" key on the French (Belgian) keyboard. I believe this is the "|\" key on the US keyboard. What is its value?
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Problem with Virtual Keys

Post by charvista »

No, it is not the "|\" key on the US keyboard, as this one is #VK_OEM_5.
The Virtual key for the "<>\" on the Belgian keyboard is #VK_OEM_102. It appears undocumented in the MSDN, but I found it in the Structure Viewer from PB!!!
Cheers
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: Problem with Virtual Keys

Post by LuCiFeR[SD] »

you are very welcome charvista. Glad I could be of assistance :)
Karig
New User
New User
Posts: 7
Joined: Mon Jul 11, 2016 10:20 pm

Re: Problem with Virtual Keys

Post by Karig »

This is an ancient thread :mrgreen: , but in case anyone's searching how to use the odd punctuation keys with AddKeyboardShortcut in Linux, here is some code that works on both my Windows machine and my Linux laptop:

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  #KEY_COMMA         = 44 ; Asc(",")
  #KEY_PERIOD        = 46 ; Asc(".")
  #KEY_SLASH         = 47 ; Asc("/")
  #KEY_SEMICOLON     = 59 ; Asc(";")
  #KEY_QUOTE         = 39 ; Asc("'")
  #KEY_LEFT_BRACKET  = 91 ; Asc("[")
  #KEY_RIGHT_BRACKET = 93 ; Asc("]")
  #KEY_BACKSLASH     = 92 ; Asc("\")
  #KEY_BACKTICK      = 96 ; Asc("`")
CompilerElseIf #PB_Compiler_OS = #PB_OS_Windows
  ; REFERENCE: http://msdn.microsoft.com/en-us/library/dd375731(VS.85).aspx
  #KEY_COMMA         = #VK_OEM_COMMA
  #KEY_PERIOD        = #VK_OEM_PERIOD
  #KEY_SLASH         = #VK_OEM_2
  #KEY_SEMICOLON     = #VK_OEM_1
  #KEY_QUOTE         = #VK_OEM_7
  #KEY_LEFT_BRACKET  = #VK_OEM_4
  #KEY_RIGHT_BRACKET = #VK_OEM_6
  #KEY_BACKSLASH     = #VK_OEM_5
  #KEY_BACKTICK      = #VK_OEM_3
CompilerEndIf
(So you can add the #PB_Shortcut_Control|#KEY_PERIOD if you want that to do something. :wink: )

I don't have a Mac, or I'd be motivated to figure out what the values should be for the Mac.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Problem with Virtual Keys

Post by netmaestro »

Nothing wrong with your code, but in PB shorthand:

',' is eqivalent to Asc(",")
BERESHEIT
Post Reply