Author Topic: Capturing keyboard input using _KEYHIT  (Read 15170 times)

0 Members and 1 Guest are viewing this topic.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
Capturing keyboard input using _KEYHIT
« on: August 28, 2018, 01:30:18 am »
I need to capture keyboard input using Inform. I see that __UI_Keyhit contains the value of any key being pressed and then released. However, __UI_Keyhit will only contain these values if a control currently has focus. I need to know key presses all the time whether a control has focus or not.

_KEYHIT will occasionally see a keystroke and I'm assuming this is because InForm is grabbing keyboard input.

Is there a way to turn off InForm's keyboard processing so _KEYHIT can grab the scan codes instead, or another method built in to InFrom that grabs keystrokes?

edit: I do realize I can use INKEY$ but would prefer to use _KEYHIT if possible.
« Last Edit: August 28, 2018, 01:33:49 am by TerryRitchie »
In order to understand recursion, one must first understand recursion.

FellippeHeitor

  • Guest
Re: Capturing keyboard input using _KEYHIT
« Reply #1 on: August 28, 2018, 01:37:31 am »
Not possible to override InForm's input survey routines. Is this to enable the numeric keypad in the upcoming calculator?
« Last Edit: August 28, 2018, 01:39:48 am by FellippeHeitor »

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
Re: Capturing keyboard input using _KEYHIT
« Reply #2 on: August 28, 2018, 01:44:44 am »
Yes, I have the keypad working fine using the mouse, no problems there.

What I am doing now is using INKEY$ then manually invoking the buttons like this:

k$ = INKEY$
IF k$ <> "" THEN
    SELECT CASE k$
        CASE "1"
            __UI_Click(but1) ' but1 is the id name I gave the button in the designer
        CASE "2"
        .
        .
        etc...

This seems to be working ok. Is there a better way or am I on the right track?
In order to understand recursion, one must first understand recursion.

FellippeHeitor

  • Guest
Re: Capturing keyboard input using _KEYHIT
« Reply #3 on: August 28, 2018, 01:47:42 am »
Looking good! _KEYHIT is, as you realized, read by InForm itself and made available via __UI_KeyHit when a control has focus. INKEY$ on the other hand is up for grabs, so your method seems proper. Are you reading the keyboard in __UI_BeforeUpdateDisplay?

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
Re: Capturing keyboard input using _KEYHIT
« Reply #4 on: August 28, 2018, 01:52:40 am »
Yep, that's exactly where I have it. Ok then, it shouldn't be long now until I'm finished with the program. Have a few history issues to deal with (in calculator there is a history of transactions above the output: 20 + 3 * 4 + 6 ...) but those should be easy to solve.

InForm is really easy to use once you get into it.

To all: if you have not tried InForm yet I hope my little example program will give you a reason to try it out. It really is a fantastic library.
In order to understand recursion, one must first understand recursion.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: Capturing keyboard input using _KEYHIT
« Reply #5 on: August 28, 2018, 12:59:51 pm »
In my gravitation simulation program (still in preparation), I am using both __UI_Keyhit and INKEY$.  Richard

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: Capturing keyboard input using _KEYHIT
« Reply #6 on: August 29, 2018, 05:30:59 pm »
Hi Fellippe
Hi Richard
Hi Terry

I bring my little experience with InForm from the old 1beta to the actual 7beta.
Already in old PongClone or AnotherBrickInTheWall I use a trick to take input from keyboard without using old INKEY$ but with _KeyHit and _Keydown.

I attached the file of example...
it seems that at starting point the application had no fullfully focus and so you must refocus each time the focus.
So in event Keypress I manage input using _keyhit or _keydown or the general variable __UI_KeyHit.
But first in event BeforeUpdate I set focus on the window of the application __UI_Focus = WindowApplicationName.

I hope it will be useful.



* [InForm]Keyboard and Focus.rar (Filesize: 4 KB, Downloads: 277)
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: Capturing keyboard input using _KEYHIT
« Reply #7 on: August 29, 2018, 06:39:12 pm »
Hi Terry
this is an addon idea that in the restrict goal of a calculator can be feasible
using buttons with Hotkey made by numbers
Sure to let work this idea you must press Alt plus key of number, but moreover you cannot catch the numbers of keypad activated by NumLock on the keyboard.

Thanks to read and to try
* [inform]numbers.rar (Filesize: 4.23 KB, Downloads: 304)
Programming isn't difficult, only it's  consuming time and coffee