Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pasting to notepad (when notepad is in background)
#1
im wanting to paste what is in my clipboard to
Code:
Select All      Help
id(15 "Untitled - Notepad")

without having that window act can this be done ?


THANK YOU

ps set text wont work for what im trying to do
Reply
#2
Code:
Select All      Help
_s.getclip
_s.setsel(0 id(15 "Notepad"))

here _s is a str variable.

Or

Code:
Select All      Help
SendMessage id(15 "Notepad") WM_PASTE 0 0
Reply
#3
im not sure how u go about doing this but here is what i im trying to do im trying to hit the back key in id(15 "Notepad") without that window being act, i tried
Code:
Select All      Help
SendMessage id(15 "Notepad") VK_BACK 0 0
that did not work
Reply
#4
Function SendKey
Code:
Select All      Help
;/
function hwnd vk [flags] ;;flags: 0 down-up, 1 down, 2 up

;Posts keyboard messages directly to a control. The window can be inactive.
;You can find virtual-key codes in QM help. For alphanumeric keys, use uppercase characters in '', eg 'A'.


;hwnd - control handle.
;vk - virtual-key code.


;EXAMPLE
;int hwnd=id(15 "Notepad")
;SendKey hwnd 'A'
;1
;SendKey hwnd VK_BACK



int m1 m2 lp=MapVirtualKey(vk 0)<<16|1
sel(vk) case [3,33,34,35,36,37,38,39,40,44,45,46,91,92,93,111,144,VK_RCONTROL,VK_RMENU] lp|0x1000000 ;;ek
if(flags&3!2) PostMessage hwnd WM_KEYDOWN vk lp
if(flags&3!1) PostMessage hwnd WM_KEYUP vk lp|0xC0000000
Reply
#5
Of course you now my next question....

Can you do this with strings?

Code:
Select All      Help
str a="This is a test."

SendKey hwnd a

At this time this is just a theoretical question, as I don't need to do it at this time. But, it is interesting.


thanks.
A new blog on QM coding and automation.

The Macro Hook
Reply
#6
Can be programmed using QmKeyCodeToVK, but easier for me would be to add a function that would use already existing internal code for key.

key2 keycodes [flags] [hwnd]
Reply
#7
How do you do this with strings?
Reply
#8
I'll add a function for this in some new QM version.
Reply
#9
Quote:in some new QM version

rats...i could actually use this now. Smile
A new blog on QM coding and automation.

The Macro Hook
Reply
#10
Is this available on 2.2.0.11?
Reply
#11
No, possibly in 2.2.1.
Reply
#12
i came across this today cuz i need to make sure that the info im trying to type into an 'OpenVMS' telnet session doesn't get stolen by something going on top if it and stealing focus.

did you create the 'sendkey' with the capacity to use strings?
thanks
A new blog on QM coding and automation.

The Macro Hook
Reply
#13
Try to send characters instead. This should work with most controls.

Function SendCharactersToWindow
Code:
Select All      Help
;/
function hwnd $_string

;Sends the string to a child window using WM_CHAR messages.
;The window can be inactive.

;hwnd - child window handle.

;EXAMPLE
;int hwnd=id(15 "Notepad")
;SendCharactersToWindow hwnd "Line1[]Line2"


str s=_string
s.findreplace("[]" "[13]")
s.unicode
word* w=s
for(_i 0 s.len/2) PostMessageW hwnd WM_CHAR w[_i] 0

EDIT: 04/28/2008 - supports Unicode. To use Unicode you also need QM 2.3.0.

Sending key messages would be easy, because now you can use key to convert QM key codes to virtual key codes. However it is not so easy. Many apps also check real key state, especially of modifier keys. One workaround would be to send messages for all keys and also use key to press modifier keys.

This function is not finished. Has synchronization problems. Also probably will not work with menus (Alt+...). Needs to work with it more. Don't use in your macros, except for testing.

EDIT: a better version: Java Accessible Object Dialog Problem

Function SendKeysToWindow
Code:
Select All      Help
;/
function hwnd ARRAY(KEYEVENT)'a

;Sends keys to a child window using WM_KEYDOWN/WM_KEYUP messages.
;The window can be inactive.
;The function actually presses modifier keys (Shift, Ctrl, Alt), although very briefly.


;hwnd - child window handle.
;a - the key function.


;EXAMPLE
;int hwnd=id(15 "Notepad")
;SendKeysToWindow hwnd key("Line1[]Line2[]")



int i lparam m up alt
ifk(A) alt=1

for i 0 a.len
,KEYEVENT k=a[i]
,
,if(k.flags&0x80) ;;wait
,,i+1
,,opt waitmsg -1
,,wait (a[i].wt/1000.0)
,,continue
,
,lparam=k.sc<<16|1
,if(k.flags&KEYEVENTF_EXTENDEDKEY) lparam|0x01000000
,if(k.flags&KEYEVENTF_KEYUP) lparam|0xC0000000; up=1; else up=0
,
,if(alt) m=iif(up WM_SYSKEYUP WM_SYSKEYDOWN); lparam|0x20000000
,else m=iif(up WM_KEYUP WM_KEYDOWN)
,
,;use key for Ctrl/Shift/Alt
,sel(k.vk)
,,case [16,17,18]
,,;out "%i %i" i k.vk
,,;if(up) key- (k.vk); else key+ (k.vk)
,,keybd_event k.vk k.sc k.flags 0
,,;0.1
,
,;out "%i 0x%08X" k.vk lparam
,;out "%i %i" k.vk RealGetKeyState(k.vk)
,PostMessage hwnd m k.vk lparam
,0.01
,
,if(k.vk=VK_MENU) alt=!up
Reply
#14
well. that first one works just dandy. my text editor (PSPad) doesn't receive the newline character ([10] or [13]) but it works in a lot of other places.

thanks!
A new blog on QM coding and automation.

The Macro Hook
Reply
#15
Sir, can you show me how to parsing Sendkey Alt+Numpad (ex.Alt+132 result->ä) to excel without activated the workbook.?
Reply
#16
Download QM 2.3.0. It supports Unicode.

Macro
Code:
Select All      Help
ExcelSheet es.Init
es.SetCell("ä" 1 1)

I also updated SendCharactersToWindow. In QM 2.3.0 now it supports Unicode.
Reply
#17
int a(131) b(132) c(133)
I mean using macro to send "key Alt + a or b or c" to excel then in excel show the â, ä or à in cell.
figured using FormatKeyString and GetMod but don't know how to use that function.
Reply
#18
Don't know how to send Alt+numpad to an inactive window.
Reply
#19
Sorry, not inactive windows, but in background. is it posible??
Reply
#20
If key cannot be used, I don't know another way to send Alt+numpad to an inactive or background window.
Reply
#21
Dear Gintaras,

Supposed that I want to send to Notepad background window, what I usually send when it is foreground window :
Quote:key AS 1

My question is how should I compose the SendKeysToWindow statement, in particular in what it concerns the Alt (A) character code.

Many thanks.
Reply
#22
In most cases Alt will not work with this function.
Macro Macro2471
Code:
Select All      Help
int w=win("Notepad")
SendKeysToWindow w key(Af)
Reply
#23
Thank you so much! It is true, I envisaged a lot of problems with Alt, particularly in Internet Exolorer Windows. No problem with VK_CONTROL and VK_SHIFT.

Best regards!
Reply
#24
Code:
Select All      Help
;/
function hwnd vk [flags] ;;flags: 0 down-up, 1 down, 2 up

;Posts keyboard messages directly to a control. The window can be inactive.
;You can find virtual-key codes in QM help. For alphanumeric keys, use uppercase characters in '', eg 'A'.

;hwnd - control handle.
;vk - virtual-key code.

;EXAMPLE
;int hwnd=id(15 "Notepad")
;SendKey hwnd 'A'
;1
;SendKey hwnd VK_BACK


int m1 m2 lp=MapVirtualKey(vk 0)<<16|1
sel(vk) case [3,33,34,35,36,37,38,39,40,44,45,46,91,92,93,111,144,VK_RCONTROL,VK_RMENU] lp|0x1000000 ;;ek
if(flags&3!2) PostMessage hwnd WM_KEYDOWN vk lp
if(flags&3!1) PostMessage hwnd WM_KEYUP vk lp|0xC0000000

I'm using the send keys code to another window. However, the window doesn't have have id. Any idea how to get around this?

int hwnd=id(15 "Notepad")
Reply
#25
If there are no controls, send keys to the window.

int hwnd=win("Notepad")

BTW, a better version of SendKeysToWindow:
Java Accessible Object Dialog Problem
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)