Author Topic: Announcing the _INKEY function!  (Read 2972 times)

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
Re: Announcing the _INKEY function!
« Reply #75 on: September 18, 2010, 03:09:35 PM »
Quote
Will the next release be released on the site or simply updated?
As both an update and a site release. Existing users can simply update.

Clippy

  • Hero Member
  • *****
  • Posts: 14398
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Announcing the _INKEY function!
« Reply #76 on: September 18, 2010, 03:42:30 PM »
Yet ANOTHER reason not to use SCREEN 0!  :D
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
Re: Announcing the _INKEY function!
« Reply #77 on: September 23, 2010, 05:29:24 AM »
I'm delighted to announce that the input upgrade is finally fully complete and I will now be devoting my time to other areas of QB64. Expect a release of QB64 within a weeks time which includes both the input upgrade and support for the FIELD statement. Talk about mixing the old with the new... but that's what QB64 does best! ;D

Clippy

  • Hero Member
  • *****
  • Posts: 14398
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Announcing the _INKEY function!
« Reply #78 on: September 23, 2010, 05:59:06 PM »
I think everybody left because they think that DEF Fn is next...  ;D

Please 'splain what happens with INP and stuff with the change. Is DOT on the list too, Lucy?

WIKI Wicardo
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
Re: Announcing the _INKEY function!
« Reply #79 on: September 24, 2010, 12:04:55 AM »
INP and INKEY$ stay the same except that they won't return the scancodes of new keys, like the Windows key. The idea behind this is for QB64 programs to work identically on any computer, so the scancodes returned will match a standard 101-key layout keyboard and not the actual physical keyboard which may be quite different.

The real winners of the input upgrade are our international users, who will be able to enter specific characters from the extended CP437 range using their keyboard without you having to modify your programs for them. Also, with UNICODE input, IME support and the UTF32 font override option all QB64 users can make multilingual QB64 programs if they choose.

It also means my response to "Blah in QB64 related to keyboard input doesn't work properly" will no longer be "I'll address this after I revise QB64's input system", because now I have revised QB64's input system.

Quote
I think everybody left because they think that DEF Fn is next
When you set a goal like 100% QBASIC compatibility, you don't say "but". I read the comments about DEF FN and I agree with the concerns raised. I've been programming in QBASIC for many years and the number of times I've accidentally named a variable 'fn....' was only once or twice, to which QBASIC soon informed me something was amiss. Supporting DEF FN is far more important in the greater scheme of things than the rare annoyance it may cause us if it was implemented. However, it isn't much of a priority. ;)

Clippy

  • Hero Member
  • *****
  • Posts: 14398
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Announcing the _INKEY function!
« Reply #80 on: September 24, 2010, 12:34:17 AM »
So how can I disable the Windows key or even find the menu key? You don't miss things until they are gone.

Short lived as it was...
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
Re: Announcing the _INKEY function!
« Reply #81 on: September 24, 2010, 07:17:12 AM »
Quote
So how can I disable the Windows key or even find the menu key?
Well, afaik, the only method of disabling the Windows key is a screwdriver. You'll be able to detect the Windows key and menu key using the new _KEYHIT function and the new _KEYDOWN function.

Cyperium

  • Hero Member
  • *****
  • Posts: 3100
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Announcing the _INKEY function!
« Reply #82 on: September 24, 2010, 07:24:41 AM »
In VB you can do that by a windows hook which pipes all the windows messages through your program and you decide which to let through or which to stop.
Venture - New Prototype, QB64 Editor v1.95b (now linux/mac compatible).

Pete

  • Moderator
  • Hero Member
  • *****
  • Posts: 5576
  • Cuz I sez so varmint!
Re: Announcing the _INKEY function!
« Reply #83 on: September 24, 2010, 08:33:31 AM »

Great, let's all _KEYDOWN with QB64.  8)

Pete

 - Pleez escuse my bad Englash

codeguy

  • Hero Member
  • *****
  • Posts: 3339
  • what the h3ll did i name that code?
    • stuff at dkm
    • Email
Re: Announcing the _INKEY function!
« Reply #84 on: September 24, 2010, 01:48:00 PM »
can't believe the array of stuff we support in qb64, everything from old-school line printers to animation (including gif). this is quite an evolution. i guess the best thing for me at least was the generous memory capacity and the ability to keep a lot of my old code almost exactly as it was. now i will go about changing all my TYPE statements (or perhaps not, as i've grown rather fond of that method). i am not good at interpreter design, so i guess it will be up to zom-b and cyperium to hammer that one out. just think if cars evolved as quickly as qb64 did. we'd be able to nearly hit light speed, get a zillion miles per gallon and all kinds of other feats entirely impossible. galleon, you have turned qb64 into an incredible virtual machine! thanks again for all your incredibly fine efforts.
« Last Edit: October 04, 2010, 06:43:43 AM by codeguy »
i want a piece of 3.141592653587932386

Clippy

  • Hero Member
  • *****
  • Posts: 14398
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Announcing the _INKEY function!
« Reply #85 on: September 24, 2010, 02:06:18 PM »
BTW, INP still returns the WRONG codes for F11 and F12. I get 5 and 6 and release codes 128 more, but release codes when pressed instead of not pressed.

QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
Re: Announcing the _INKEY function!
« Reply #86 on: October 04, 2010, 12:47:31 AM »
This example program demonstrates how to interpret the return value from the new QB64 _KEYHIT function.
Note: The font cyberbit.ttf is free for non-commercial usage and will be bundled with QB64 from now onwards. It is only required to facilitate input via IME and not loaded unless the user switches to an IME input system mode. As QB64 also uses locates several fall-back Windows fonts under circumstances when 'cyberbit' is not present, it is unnecessary to distribute this font with your programs.
Code: [Select]
SCREEN _NEWIMAGE(800, 600, 8)
DEFLNG A-Z

CLS , 1

font = _LOADFONT("cyberbit.ttf", 24)
unifont = _LOADFONT("cyberbit.ttf", 24, "UNICODE")
_FONT font

DO

    x = _KEYHIT

    IF x THEN

        IF x < 0 THEN
            COLOR 2
            PRINT "Released ";
            x = -x
        ELSE
            COLOR 10
            PRINT "Pressed ";
        END IF

        IF x < 256 THEN
            PRINT "ASCII "; x;
            IF x >= 32 AND x <= 255 THEN PRINT "[" + CHR$(x) + "]" ELSE PRINT
        END IF

        IF x >= 256 AND x < 65536 THEN
            PRINT "2-BYTE-COMBO "; x AND 255; x \ 256;
            x2 = x \ 256
            IF x2 >= 32 AND x2 <= 255 THEN PRINT "[" + CHR$(x2) + "]" ELSE PRINT
        END IF

        IF x >= 100000 AND x < 200000 THEN
            PRINT "SDL VK"; x - 100000
        END IF
        IF x >= 200000 AND x < &H40000000 THEN
            PRINT "QB64 VK"; x - 200000
        END IF

        IF x >= &H40000000 THEN
            PRINT "UNICODE "; x - &H40000000; "0x" + HEX$(x - &H40000000) + " ...";
            cx = POS(1): cy = CSRLIN
            _FONT unifont
            LOCATE cy, cx
            COLOR 15
            z$ = MKL$(x - &H40000000) + MKL$(0)
            PRINT z$ + z$ + z$;
            _FONT font
            LOCATE cy, 1: PRINT
        END IF

    END IF

LOOP

Clippy

  • Hero Member
  • *****
  • Posts: 14398
  • I LOVE π = 4 * ATN(1)    Use the QB64 WIKI >>>
    • Pete's Qbasic Site
    • Email
Re: Announcing the _INKEY function!
« Reply #87 on: October 04, 2010, 02:52:19 AM »
Wow, next week came fast!

I'll give er a shot

Oh boy, that should be one hell of a chart! I think I'll just put your example there!

Pause/Break returns SDL 19, but only after another key is pressed. Nothing on press.

Everything else seems normal. Hope to get some input from Cy soon.

DARN, I gotta add K to the alphabet list! Maybe I'll just add an underscore instead.

DONE!

Ted

« Last Edit: October 04, 2010, 04:20:58 AM by Clippy »
QB64 WIKI: Main Page
Download Q-Basics Code Demo: Q-Basics.zip
Download QB64 BAT, IconAdder and VBS shortcuts: QB64BAT.zip
Download QB64 DLL files in a ZIP: Program64.zip

Galleon

  • Administrator
  • Hero Member
  • *******
  • Posts: 4226
  • QB Forever
    • Email
Re: Announcing the _INKEY function!
« Reply #88 on: October 04, 2010, 07:22:45 AM »
An important difference between INKEY$ and _KEYHIT I should point out to everyone is how they work when CTRL, ALT or SHIFT are used. INKEY$ returns a different code if you hold down CTRL, ALT or SHIFT before pressing (for example) F1. _KEYHIT will return the same code regardless of which modifiers were used but you can check _KEYDOWN to see which modifying keys are being used.

Consider the following example:
Code: [Select]
CONST KEY_RSHIFT& = 100303
CONST KEY_LSHIFT& = 100304
DO

    x = _KEYHIT
    IF x = CVI(CHR$(0) + CHR$(59)) THEN
        IF _KEYDOWN(KEY_LSHIFT) OR _KEYDOWN(KEY_RSHIFT) THEN
            PRINT "KEYHIT: SHIFT+F1"
        ELSE
            PRINT "KEYHIT: F1"
        END IF
    END IF

    k$ = INKEY$
    IF k$ = CHR$(0) + CHR$(59) THEN PRINT "INKEY$: F1"
    IF k$ = CHR$(0) + CHR$(84) THEN PRINT "INKEY$: SHIFT+F1"

LOOP

Also, this is a very useful code snippit you might like to have handy for interpreting some of the new key values returned by _KEYHIT and for use with _KEYDOWN:
Code: [Select]
CONST KEY_PAUSE& = 100019
CONST KEY_NUMLOCK& = 100300
CONST KEY_CAPSLOCK& = 100301
CONST KEY_SCROLLOCK& = 100302
CONST KEY_RSHIFT& = 100303
CONST KEY_LSHIFT& = 100304
CONST KEY_RCTRL& = 100305
CONST KEY_LCTRL& = 100306
CONST KEY_RALT& = 100307
CONST KEY_LALT& = 100308
CONST KEY_RMETA& = 100309 'Left 'Apple' key (MacOSX)
CONST KEY_LMETA& = 100310 'Right 'Apple' key (MacOSX)
CONST KEY_LSUPER& = 100311 'Left "Windows" key
CONST KEY_RSUPER& = 100312 'Right "Windows"key
CONST KEY_MODE& = 100313 '"AltGr" key
CONST KEY_COMPOSE& = 100314
CONST KEY_HELP& = 100315
CONST KEY_PRINT& = 100316
CONST KEY_SYSREQ& = 100317
CONST KEY_BREAK& = 100318
CONST KEY_MENU& = 100319
CONST KEY_POWER& = 100320
CONST KEY_EURO& = 100321
CONST KEY_UNDO& = 100322

Quote
Pause/Break returns SDL 19, but only after another key is pressed. Nothing on press.
That's because the pause key in QBASIC pauses your program and QB64 is deliberately hiding the press information. I'll make it hide the release information in this case as well. Nicely spotted.

Cyperium

  • Hero Member
  • *****
  • Posts: 3100
  • Knowledge is good, but understanding is better
    • Cyperium
    • Email
Re: Announcing the _INKEY function!
« Reply #89 on: October 04, 2010, 11:29:59 AM »
I tried all the _KEYHIT functions I could find (three, in this thread) and they all work as expected on my Swedish Keyboard!

I still can't type $ and \ in the IDE though (which is annoying since they are very commonly used) but you said that not all had been implemented yet so I'm eagerly awaiting them.

This is the output of _KEYHIT when pressing ALT Gr + "+" which is the \.
Pressed SDL VK 306
Pressed SDL VK 307
Pressed ASCII 92 [\]
Released ASCII 92 [\]
Released SDL VK 306
Released SDL VK 307

And this is the output of _KEYHIT when pressing ALT Gr + "4" which is $.
Pressed SDL VK 306
Pressed SDL VK 307
Pressed ASCII 36 [$]
Pressed ASCII 36 [$]
Released SDL VK 306
Released SDL VK 307


I thought it might help. ÅÄÖ works fine in the IDE though!


Other things that currently doesn't work in the IDE are @, {, [, ] and }. But they aren't as important as $ and \.
Venture - New Prototype, QB64 Editor v1.95b (now linux/mac compatible).