Author Topic: Simulating keys pressed and mouse movement etc  (Read 3881 times)

0 Members and 1 Guest are viewing this topic.

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Simulating keys pressed and mouse movement etc
« on: November 14, 2020, 10:50:09 pm »
I thought I saw somewhere how to insert key strokes actually simulated by a program (not a person) into the keyboard buffer and then continue from the buffer as if a person just did the keystrokes.

Similarly to "insert" mouse movements and "click".

Anyone have any relevant references?

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Simulating keys pressed and mouse movement etc
« Reply #1 on: November 15, 2020, 01:39:06 am »
_SCREENCLICK will punch the mouse anywhere on the screen, even outside your window.
I'm using it to click the minimize button.  I needed _SCREENX, _SCREENY, and_WIDTH
to compute where to click.  Some situations may need the use of _HEIGHT, _DESKTOPWIDTH,
or _DESKTOPHEIGHT.

I have no clue how to stuff the keyboard buffer, tho clearly you can change the focus
to some other program with the above.
It works better if you plug it in.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Simulating keys pressed and mouse movement etc
« Reply #2 on: November 15, 2020, 01:42:42 am »
_SCREENPRINT will simulate keypresses for you.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: Simulating keys pressed and mouse movement etc
« Reply #3 on: November 15, 2020, 01:55:34 am »
@ Richard

Thanks -  _SCREENCLICK (etc) sounds like exactly all that I need for the mice side of things (hope it will also work with "TouchPads" (built in "mouse" (sort of) as supplied with many laptops).

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: Simulating keys pressed and mouse movement etc
« Reply #4 on: November 15, 2020, 02:10:16 am »
@ Steve

Thanks for reply.

In using _SCREEENPRINT, I assume that only standard 7-bit ASCII (above CHR$(&h20)) can be used - such as A-Z 0-9 +-=-() etc and the Ctrl +A (etc) for control codes as mentioned in the IDE help Screen.

How to (if possible) simulate say CTRL +,  Ctrl -, Fn Alt Ctrl Shift WindowsKey F1-F12 numeric keypad etc etc which may be used as SINGLE, DOUBLE TRIPLE etc key combos?

FellippeHeitor

  • Guest
Re: Simulating keys pressed and mouse movement etc
« Reply #5 on: November 15, 2020, 04:51:13 am »
For anything deeper related to screen macros I recommend using AutoHotKey: https://www.autohotkey.com/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Simulating keys pressed and mouse movement etc
« Reply #6 on: November 15, 2020, 11:39:02 am »
One note about _SCREENCLICK, you may want to consider _DELAY .05 to separate clicks. Also, be careful what you want on the desktop is there, before you click. This can be accomplished by running a check routine if you are using SHELL _DONTWAIT to open a third party app. If the app doesn't open before the _SCREENCLICK initiates, you're screwed.

In regard to simulating key input, if you are using a Windows system, you can fiddle around with the API. The Wiki has some examples of this, by Dav. I believe the API uses SendInput(). Anyway, here are a couple of off-site references...

https://www.codeproject.com/tips/506147/easy-way-to-simulate-keyboard-press-and-release-ke

https://stackoverflow.com/questions/5607849/how-to-simulate-a-key-press-in-c

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Simulating keys pressed and mouse movement etc
« Reply #7 on: November 15, 2020, 11:03:33 pm »
OK You can use DOS interrupt 16h

INT 16 - AH = 05h KEYBOARD - WRITE TO KEYBOARD BUFFER (AT model 339,XT2,XT286,PS)
CH = scan code
CL = character
Return: AL = 1 if buffer full

Ok the ENTER key is 13(decimal) (carriage return)
« Last Edit: November 16, 2020, 02:27:11 am by NOVARSEG »

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: Simulating keys pressed and mouse movement etc
« Reply #8 on: November 16, 2020, 12:29:26 am »
@ NOVARSEG

Thanks for your reply.

I will give your method a try.

Its been a long time since I did anything with Interrupts - when I did do so, it was using MS PDS 7.1 (an upgrade to MS QB45), and being 16 bit environment - one could do "all sorts of things". Nowadays with Windows 10 I think there are very strict restrictions on interrupt calls and although I have not read deeply into QB64 Wiki - the QB64 emulation for interrupts is very limited (maybe bare-bones Mouse related only I think - I hope that I am wrong).

So I hope that I can form a list of ALL the keys scan codes (including WindowsKey, Fn and F1-F12 etc etc - my hard copy list from DOS 3 is not detailed enough). My HP laptop has i7 processor and I have no idea on any of the keyboard details.
« Last Edit: November 16, 2020, 04:42:09 am by Richard »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Simulating keys pressed and mouse movement etc
« Reply #9 on: November 16, 2020, 02:07:21 am »
Richard

Ya I did  a strange thing with that interrupt once.. I managed to use the DIR command from within  a Quick Basic program.   

If you got XP  you can still run the 16 bit programs.  Dont know how QB64 would compile that.



« Last Edit: November 16, 2020, 02:18:46 am by NOVARSEG »