BBC BASIC for Windows
Programming >> BBC BASIC language >> Ctrl/Tab in program http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1393493563 Ctrl/Tab in program
Post by brian658 on Feb 27th, 2014, 08:32am
I need to copy the output window to the clipboard (as text using Ctrl/Tab). How can I do this from within the program? I've tried 'faking' the keyboard input with Ctrl/Tab with no success. Can it be done? Kind regards......
Re: Ctrl/Tab in program
Post by admin on Feb 27th, 2014, 3:19pm
I need to copy the output window to the clipboard (as text using Ctrl/Tab). How can I do this from within the program? I've tried 'faking' the keyboard input with Ctrl/Tab with no success. Can it be done?
Instead of faking keyboard input, which should work but is a bit messy, you can loop through the characters yourself using GET(x,y) or GET$(x,y) and assemble them back into a string, which you can then put on the clipboard.
But since you have presumably output whatever is displayed yourself, it might be easier to use *SPOOL to copy the output to a file at the same time as you display it, saving you the trouble of reading the screen at all.
Richard.
Re: Ctrl/Tab in program
Post by brian658 on Feb 28th, 2014, 08:44am
Thanks Richard, I hadn't thought of using GET(x,y) or GET$(x,y). It works for me but I still have a real preference for stuffing the Ctrl/Tab into the keyboard buffer method. It works brilliantly when I physically press the key combination but I couldn't get it coded (a test extract using yet another of your fine examples from 2006):
CLS PRINT "ABCDEFG"
test$ = CHR$(17) + CHR$(9) + CHR$(13) FOR I% = 1 TO LEN(test$) PROCfake(ASC MID$(test$ ,I%)) NEXT
END
DEF PROCfake(C%) : LOCAL V% SYS "VkKeyScan", C% TO V% IF V% AND &100 SYS "keybd_event", 16, 0, 0, 0 IF V% AND &200 SYS "keybd_event", 17, 0, 0, 0 IF V% AND &400 SYS "keybd_event", 18, 0, 0, 0 SYS "keybd_event", V% AND &FF, 0, 0, 0 SYS "keybd_event", V% AND &FF, 0, 2, 0 IF V% AND &400 SYS "keybd_event", 18, 0, 2, 0 IF V% AND &200 SYS "keybd_event", 17, 0, 2, 0 IF V% AND &100 SYS "keybd_event", 16, 0, 2, 0 ENDPROC
I'm guessing that my codes for the Ctrl, Tab and CR respectively are incorrect.
Any thoughts?
Re: Ctrl/Tab in program
Post by admin on Feb 28th, 2014, 4:04pm
It works brilliantly when I physically press the key combination but I couldn't get it coded
PROCfake isn't appropriate because it takes as a parameter the ANSI code for the character you want to send, and Ctrl+Tab does not have a corresponding character code.
Instead you can call keybd_event directly for the sequence: Ctrl Down, Tab Down, Tab Up, Ctrl Up. That should work, but bear in mind that it suffers from the fundamental weakness of faking keyboard input: you can never guarantee where the faked input will end up (it's possible that the input 'focus' may change to another window or program before or during the sequence).