Qbasicnews.com

Full Version: Sending data to keyboard?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I'm no master of the OUT command (assuming that's what's used for this), so maybe somebody here can help me:

I'm trying to figure out how to manipulate data in such as way as to make it seem to be coming from the keyboard.

I've got a barcode scanner that hooks up RS232 (Com1 on my comp). My program opens up Com1 via the OPEN command, reads data from it, and displays it to the screen.

This part works. I can scan a barcode with the scanner, and it appears on the screen fine (via PRINT command).

What I want is to be able to, say, open Notepad and read a barcode with the scanner, and have the text appear in Notepad.

I think this might be possible by having my program run in the background, reading data from COM1: and sending it to the port that the keyboard hooks up to. Correct me if I'm wrong.

If anybody know how to do this, or has any suggestions, etc, please let me know.

Thanks in advance,

Meg.

(*peace*)
I can't really help you but I doubt QB is the way to go...
I think you should search for facts about TSR's
(Terminate and Stay Resident, a program that
loads itself in memory, hooks up on a event function and ends, but
the program stays in memory and gets called everytime the event
it hooked up on is executed -I think)
You can stuff keystrokes with QB, but they will only be "faked" in the DOS box...they won't show up in Windows. If you really want to use QB, you can copy the text to the clipboard with an interrupt and then paste it in notepad...not exactly the same though.

However, if you use VB, you can stuff keystrokes in Windows...
Yeah, in VB the code would be almost the same (the QB part) _AND_ the keystrokes can be generated with 1 line of code (windows API).
Thanks everyone for the prompt replies.

I might look into the VB thing, although I see there are some existing "software keyboard wedges" out there that do this exact thing for a fairly cheap cost, so I might just grab one of those instead.

If I do try to write something up in VB, what's the single line of code used to stuff the kb data?

*peace*

Meg.
Ok guys take it easy now. Dont kill me. I am not preaching any language here... :rotfl:

Meg, I suggest you use C since I see you here asking about low level stuff.

*Runs to his closet and puts on his helmet Wink*

*Wham Bam! !$@%^$kill him!#$@$#@*

*Ends up in the hospital*
No low level, my friend Wink Just one call: SendKeys.

For example, this code

Code:
SUB Main()
   Shell "notepad", vbNormalFocus
   SendKeys "Hey, there's a ghost in your desktop"
END SUB

Will open Notepad and write on it Wink

There are special codes for special keys:

BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

So if you wanna generate for example a code and then ENTER, you just...

Code:
SendKey code$+"{ENTER}"

Me and Phobeous used this to write a Smart Card reader in VB last year at college Wink. It just read the data from the COM port, interpreted it, and sent the keys to MSIE to validate people remotely.
MEG,
The following should work if you are running form the MSDOS prompt.
Code:
' The following is from Ethan Winer's book.
'StuffBuffer subprogram shown below inserts a string of up to 15 characters
'directly into the keyboard buffer.  It works by poking each character one
'by one into the buffer address in low memory.  Thus, when your program ends
'the characters are there as if someone had typed them manually.

DEFINT A-Z
DECLARE SUB StuffBuffer (Cmd$)

SUB StuffBuffer (Cmd$) STATIC

  '----- Limit the string to 14 characters plus Enter and save the length.
  Work$ = LEFT$(Cmd$, 14) + CHR$(13)
  Length = LEN(Work$)

  '----- Set the segment for poking, define the buffer head and tail, and
  '      then poke each character.
  DEF SEG = 0
  POKE 1050, 30
  POKE 1052, 30 + Length * 2
  FOR X = 1 TO Length
    POKE 1052 + X * 2, ASC(MID$(Work$, X))
  NEXT

END SUB
She wants to send the keystrokes to a Windows program though (Notepad)...so that won't work.
Na_th_an, thanks a bunch, and everybody else who contributed.

*peace*

Meg.
Pages: 1 2