Keypress For Outside BB4W

Discussions related to network, internet and socket programming; also to serial, parallel, Bluetooth, USB etc.
MattC
Posts: 114
Joined: Mon 16 Apr 2018, 06:17

Keypress For Outside BB4W

Post by MattC »

Hi

The answer to this may be staring me in the face. If it is, I apologise.

I'm looking for a way to initiate a virtual keypress (specifically, F9, in this case) at a certain time (or time gap) so that an external application would see it as a genuine keypress. At the moment, the app does its duty until I press the 'stop' (F9) key. However, I would often be away from the desk at the appropriate time. (The actual timing is not critical, but ideally within a few minutes.) I therefore thought it might be possible to run a small BBC program in the background that sends a keypress signal to the system that the app would pick up. Is there a way?

Matt
DDRM

Re: Keypress For Outside BB4W

Post by DDRM »

MattC
Posts: 114
Joined: Mon 16 Apr 2018, 06:17

Re: Keypress For Outside BB4W

Post by MattC »

Without checking it extensively and with minimal testing, this only seems to output the character to the output window. I tried sending a character out, while having Notepad in focus. The result was simply that the character was sent to the output window.

Matt
DDRM

Re: Keypress For Outside BB4W

Post by DDRM »

Hmm. This may be rubbish, so if it is, feel free to ignore it.

Thinking about it, the "other app" will presumably be running in a separate process, and may have its own keyboard buffer? I suspect that Windows (assuming that's what you are using, but probably true with other modern OS's, too) effectively "sandboxes" them. You could try finding the other app's handle (is it the active window? You might be able to get its handle with GetForegroundWindow), and then sending (probably actually posting) it a message, perhaps WM_CHAR?

Best wishes,

D
MattC
Posts: 114
Joined: Mon 16 Apr 2018, 06:17

Re: Keypress For Outside BB4W

Post by MattC »

Yes, it's Windows. My guess about the separate processes was the same. However, I was hoping that there was an easier route to issuing a system-wide character input. I'm guessing the keyboard driver / Windows does something like this. The app is not necessarily the foreground window. Unfortunately, this might be a little beyond me, now. I was hoping for a simple, quick fix (as always), but I have a feeling that, even if it's possible, it might be too complicated for my little brain cell. Unless you/someone has other ideas.

Thanks all the same.

Matt
DDRM

Re: Keypress For Outside BB4W

Post by DDRM »

Does this help?

Code: Select all

      REPEAT
        WAIT 100
        SYS "GetForegroundWindow" TO hw%
        PRINT hw%
        REM program has input focus
        IF hw% = @hwnd% THEN
          PRINT "This window!"
          SYS "PostMessageA",hw%,&102,65,0
          q$=GET$
          PRINT q$
        ENDIF
      UNTIL FALSE
This only prints an "A" to the input stream for its OWN window, but it works (the GET$ picks it up).

It follows that the program you are writing to needs to be LOOKING for input.

Note that this approach only sends a single character (and you might need to use the scan code, which I don't know, in the last parameter to post F9).