Faking Keypresses

Question:

From: "Steve White"
Subject: Entering text in another apps icon
Date: 29 July 2003 13:38

Hello there

I'm using BASIC (& WimpWorks), and a novice at programming. Could anyone tell me how to enter text in another application's writable icon - I wish to do this from my own app by pressing a button. An explanation of how/why it works would also be great as it will help me a lot in learning (I'd like to know what is going on as rather than just 'doing it'!).

Many thanks for any suggestions.

Cheers Steve

The Answer:

From: "Nemo"
Subject: Re: Entering text in another apps icon
Date: 29 July 2003 14:06

Anything you insert into the keyboard buffer using OS_Byte,138,0,<keypress> will get delivered to whoever owns the caret (cursor). Actually it isn't as simple as you might hope, because ancient BBC Micro fiddles mean that "international" characters (anything with bit7 set, plus character 0) must be preceded by a zero, hence:

DEF PROCsend(A$)
  LOCAL C%,Z%
  IF A$="" THEN ENDPROC
  FOR Z%=1 TO LEN(A$)
    C%=ASC(MID$(A$,Z%,1))                            ascii code of character
    IF C%=0 OR (C%AND128) THEN SYS"OS_Byte",138,0,0  if 0 or bit 7 set, send 0
    SYS"OS_Byte",138,0,C%                            now send the character
  NEXT
ENDPROC

Alternatively, you can use Wimp_ProcessKey to send keypresses - this has the advantage that you don't need to mess about as above, but because the Wimp doesn't operate a key buffer you will have to send one keypress at a time on a null event, polling between each.


Source: comp.sys.acorn.programmer
Publication: comp.sys.acorn.programmer
Contributors: Steve White , Nemo