Results 1 to 8 of 8

Thread: console_inkey & full keyboard support

  1. #1

    console_inkey & full keyboard support

    Hi folks,

    I have problems with console_inkey. It works fine with most of the keyboard, but I don't get
    anything returned for some keys, like "." or "+".
    Is this a known issue?

    Kind regards,
    Oli

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,792
    Rep Power
    10

    Re: console_inkey & full keyboard support

    Ciao oli and welcome to thinBasic community.

    Console_Inkey, in case of extended keyboard pressing, returns a 2 bytes string where first byte is null while second byte is the virtual-key code.
    You can get values of virtual-key codes from http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx

    Unfortunately I've setup virtual-key codes in UI module and not in Console module. And also I've forgot to add OEM virtual-key codes (I will add in next update).
    I will consider to move those virtual-key codes in thinBasic Core engine so they will be available to all modules.


    Anyway, "." and "+" and other codes are :
    [code=thinbasic]%VK_OEM_PLUS = &HBB ' "+" any country
    %VK_OEM_COMMA = &HBC ' "," any country
    %VK_OEM_MINUS = &HBD ' "-" any country
    %VK_OEM_PERIOD = &HBE ' "." any country[/code]

    So your code can be something like:
    [code=thinbasic]
    Uses "Console"

    dim s as string
    dim i as long

    %VK_OEM_1 = &HBA ' ";:" for US
    %VK_OEM_PLUS = &HBB ' "+" any country
    %VK_OEM_COMMA = &HBC ' "," any country
    %VK_OEM_MINUS = &HBD ' "-" any country
    %VK_OEM_PERIOD = &HBE ' "." any country


    PrintL "Please press 'q' to exit."

    DO
    s = Console_InKey()
    sleep(0)
    i = len(s)
    select case i
    case 1
    PrintL "You pressed the " + s + " key."
    case 2
    Print "You pressed an extended key: " + Hex$(Asc(s, 2))
    '--Check second char of returned string
    Select Case Asc(s, 2)
    Case %VK_OEM_PLUS
    PrintL " + (plus)"
    Case %VK_OEM_COMMA
    PrintL " , (comma)"
    Case %VK_OEM_MINUS
    PrintL " - (minus)"
    Case %VK_OEM_PERIOD
    PrintL " . (period)"
    Case Else
    PrintL " ... something else"
    End Select
    case 3
    select case asc(right$(s, 1))
    case %CONSOLE_MOUSE_MOVED
    PrintL "You moved the mouse to" + Str$(Asc(LEFT$(s,1))) + "," + LTrim$(Str$(Asc(Mid$(s, 2,1))))
    case %CONSOLE_DOUBLE_CLICK
    PrintL "You double clicked to" + Str$(Asc(LEFT$(s,1))) + "," + LTrim$(Str$(Asc(Mid$(s, 2,1))))
    case %CONSOLE_LBUTTON
    PrintL "You pressed the left button"
    case %CONSOLE_RBUTTON
    PrintL "You pressed the right button"
    case %CONSOLE_MBUTTON
    PrintL "You pressed the middle button"
    case %CONSOLE_MOUSE_WHEELED
    PrintL "Mouse wheeled"
    end select
    end select
    LOOP UNTIL (i OR s = "q")

    [/code]

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,792
    Rep Power
    10

    Re: console_inkey & full keyboard support

    Quote Originally Posted by Eros Olmi
    Unfortunately I've setup virtual-key codes in UI module and not in Console module. And also I've forgot to add OEM virtual-key codes (I will add in next update).
    I will consider to move those virtual-key codes in thinBasic Core engine so they will be available to all modules.
    In latest thinBasic beta 1.7.0 all %VK_* virtual-key codes have been moved from UI module to Core module so they will be available to all modules. Also added missing codes.
    See http://community.thinbasic.com/index...21972#msg21972 for instruction on how to get last beta version.

    With latest thinBasic beta previous example become:
    [code=thinbasic]
    Uses "Console"

    Dim s As String
    Dim i As Long

    PrintL "Please press 'q' to exit."

    Do
    s = Console_InKey()
    sleep(0)
    i = len(s)
    select case i
    case 1
    PrintL "You pressed the " + s + " key."
    case 2
    Print "You pressed an extended key: " + Hex$(Asc(s, 2))
    '--Check second char of returned string
    Select Case Asc(s, 2)
    Case %VK_OEM_PLUS
    PrintL " + (plus)"
    Case %VK_OEM_COMMA
    PrintL " , (comma)"
    Case %VK_OEM_MINUS
    PrintL " - (minus)"
    Case %VK_OEM_PERIOD
    PrintL " . (period)"
    Case Else
    PrintL " ... something else"
    End Select
    case 3
    select case asc(right$(s, 1))
    case %CONSOLE_MOUSE_MOVED
    PrintL "You moved the mouse to" + Str$(Asc(LEFT$(s,1))) + "," + LTrim$(Str$(Asc(Mid$(s, 2,1))))
    case %CONSOLE_DOUBLE_CLICK
    PrintL "You double clicked to" + Str$(Asc(LEFT$(s,1))) + "," + LTrim$(Str$(Asc(Mid$(s, 2,1))))
    case %CONSOLE_LBUTTON
    PrintL "You pressed the left button"
    case %CONSOLE_RBUTTON
    PrintL "You pressed the right button"
    case %CONSOLE_MBUTTON
    PrintL "You pressed the middle button"
    case %CONSOLE_MOUSE_WHEELED
    PrintL "Mouse wheeled"
    end select
    end select
    LOOP UNTIL (i OR s = "q")
    [/code]

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    Re: console_inkey & full keyboard support

    Hi Eros,

    wow that was really quick
    I thought extended keyboard codes are for Ctrl, Shift etc only, so my code didn't correctly evaluate the string returned by console_inkey.
    Thanks, I'll adapt my code using the new beta version.

    Bye,
    Oli

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,792
    Rep Power
    10

    Re: console_inkey & full keyboard support

    Quote Originally Posted by oli
    wow that was really quick
    That is our way of working here in thinBasic.
    If we can do something we do our best to do it as soon as possible so programmers can immediately take advantage of it.
    Sometimes we are able to be quick sometimes not. In any case those kind of request also let us improve thinBasic language and docs.

    Quote Originally Posted by oli
    I thought extended keyboard codes are for Ctrl, Shift etc only, so my code didn't correctly evaluate the string returned by console_inkey.
    Under DOS yes: plus, minus, comma, point were standard char but under Windows with the many type of keyboards and the many international symbol, they are special key chars.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6

    Re: console_inkey & full keyboard support

    Hi Eros,

    my code works now perfect, except I don't know how to handle shift, ctrl, alt + some_key.
    For example lets say I want to get shift + "-" instead of "-".
    Inkey first returns a code for shift, and then for "-", and the code for "-" is the same regardless if shift is pressed or not.
    So I guess I have to check if shift was pressed, but this is quite hard because I don't know if it was released in the meantime.
    And what is also strange to me is that if I hold shift down, Inkey returns shift codes all the time.

    Can you help me?

    Bye,
    Oli

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,792
    Rep Power
    10

    Re: console_inkey & full keyboard support

    A way could be to use GetAsyncKeyState(vKey) function (defined into UI module) and check if a keyboard key is pressed or not.
    GetAsyncKeyState(%VK_SHIFT) can return %TRUE if SHIFT is pressed when function is executed.

    To use GetAsyncKeyState function add
    [code=thinbasic]USES "UI"[/code]
    at the beginning of your script.

    Plus change your code to something like (just as an example on how to use it):
    [code=thinbasic]Select Case Asc(s, 2)
    Case %VK_OEM_PLUS
    PrintL " + (plus)" & IIf$(GetAsyncKeyState(%VK_SHIFT), " + SHIFT", "")[/code]

    Maybe I can add a console version of GetAsyncKeyState so it is not necessary to use UI module. Something like: Console_GetAsyncKeyState

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #8

    Re: console_inkey & full keyboard support

    Hi Eros,

    whoah that's great, I like thinBasic more and more
    Honestly said, I spent 2 days studying TBGL, leaving console stuff a bit aside
    I'll return this evening to the console project to add special key handling (shift etc)
    as suggested by you.

    Bye,
    Oli

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •