May 09, 2024, 03:55:33 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Sending Keystrokes...

Started by tjs, December 17, 2006, 11:02:01 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tjs

Forgive me if you have already covered this , but...

Is it possible to send Keystrokes to Windows (in my case, Ctrl+V.. Paste) from within EBasic?

For example, from within EBasic, can I 'tell' Windows Notepad to automatically 'Paste-In' some text (having run it...the easy part) that's what I'm trying to achieve...auto 'Paste' into Notepad???

Thanks P.

tjs
www.midwavi.com The home of MidWavi Pro - Sound~Video~Graphics

Mike Stefanik

There's different methods to send keystrokes to an application, but something to keep in mind is that certain methods won't work correctly under Windows Vista because of the new security model. For example, you can't send messages directly to other applications that are running at a higher privilege level. If your application depends on journal hooks, message filtering, etc. then most likely it will fail because of restrictions on APIs which allow one process to try and control another and/or inject code into its address space.
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Copex

Hi,

Is this any good to you, it may not be the best way to search for a window but it will load notepad and send some text
to the window, try msdn for more info on sending messages to windows.



Declare Import,FindWindowA(lpClassName:Pointer,lpWindowName:Pointer),Int
$Include "Windows.inc"

int chwnd

openconsole
'Load Notepad
System "C:\\WINDOWS\\NOTEPAD.EXE"
_sleep(2000) ' wait for notepad to load

while FindWindowA(Null,"Untitled - Notepad") = null
_sleep(1000)
wend

Print "Notepad Loaded"
_sleep(500)

chwnd = FindWindowA(NULL,"Untitled - Notepad")
'Get handle for window
hcid = _FindWindowEx(chwnd,0,"Edit","")
'Get handle for Edit
If hcid
SendMessage(hcid,WM_SETTEXT,0,"Hello how are you today")
'send message to notepad
print "text sent to window"
endif

Print "Press any key to exit"
do:until inkey$ <> ""
closeconsole
end
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

seberbach

TJS:  Here is a typical reaction to the sendkeys issue.

http://m8software.com/developer/keysend/sendkey.htm

Apparently people will step up and pay good money if you do a good job with this.

I played around with Handlespy and messages, but sending messages will be a problem in future with Microsoft changing the OS.

I like Copex's example,  I am still struggling with  Ctrl-C and Ctrl-V, without much success.

My suggestion would be to invoke a sendkeys program from the OS shell ( there are several on google, and that might be more compatible for linux someday),
or go whole-hog and use Auto-it DLL if you are sticking with Windows..  I recall seeing a translation for Auto-It header posted in thew old IBasic Forum to help save you time. Then you can use EBasic to integrate applications together using a script.

I plan to work with this in the future, sorry I can't hand it over just now.

The advantage is that AutoIt will have to be updated for Vista, if it has not been already.  You can use other people's hard work to help solve your problem.

Best,

Steve Eberbach

P.S.

Paul, your Ebasic window appears in HandleSpy as Class: IBasicWndClass

Maybe it should be changed to EBasicWndClass?


Ionic Wind Support Team

That was done for compatibility as some code depends on the class name of the window.  It will be changed though in 1.6.
Ionic Wind Support Team

Copex

This code will toggle the number lock key......


'keybd_event Function... see
'http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/keybd_event.asp
'Or
'http://www.codeproject.com/system/keyboard.asp
'for more infomation

$include "windows.inc"

openconsole

SetNumLock( TRUE )
Print "press any key to end"

do:until inkey$ <> ""
closeconsole
end
'---------------------------------------------------------------------------------
sub SetNumLock(bState as int)

      def keyState[255]:int
 
if  _GetKeyboardState(keyState) <>0

      ' Simulate a key press
         _keybd_event( VK_NUMLOCK,0x45,KEYEVENTF_EXTENDEDKEY | 0,0 )

      ' Simulate a key release
         _keybd_event( VK_NUMLOCK,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0)
print "numberloack toggled"
endif
return
endsub

-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/