Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Waiting for Ctrl+Up
#1
I wrote a little program to swap a window between monitors. It was handy enough to convert to an .exe to send to a friend. Because .exe don't support triggers I built in a wait for key event. My hot key is Ctrl-Up, but it catches the Ctrl alone. How can I wait for CU. Here's the code:
Code:
Copy      Help
int hand
int x y cx cy

mes "Running"

rep
,wait 0 KF CU ;; wait for Ctrl+Up
,
,hand=win
,GetWinXY hand x y cx cy ;;get window location
,,;Deb
,,if x > ScreenWidth-5 ;; if on primary monitor, send to secondary
,,,res hand
,,,mov 0 0 hand
,,,0.1
,,,max hand
,,else                ;; if on secondary monitor, send to primary
,,,res hand
,,,mov ScreenWidth 0 hand
,,,0.1
,,,max hand    
,,,
,,act hand


Thanks,
Matt B
Matt B
#2
Wait for Up, and then

if(GetMod!=2) key+ U; continue

Not tested.

Or, instead of

rep
,wait 0 KF CU ;; wait for Ctrl+Up

Use RegisterHotKey:
Code:
Copy      Help
def MOD_ALT 0x0001
def MOD_CONTROL 0x0002
def MOD_SHIFT 0x0004
def MOD_WIN 0x0008

if(!RegisterHotKey(0 1 MOD_CONTROL VK_PRIOR)) end "RegisterHotKey 1 failed"
if(!RegisterHotKey(0 2 MOD_CONTROL VK_NEXT)) end "RegisterHotKey 2 failed"
;...

MSG m
rep
,if(GetMessage(&m 0 0 0)<1) ret
,sel m.message
,,case WM_HOTKEY
,,sel m.wParam
,,,case 1
,,,out "hotkey 1"
,,,case 2
,,,out "hotkey 2"
,,,
,,

The example registers 2 hotkeys. You need only 1.
#3
Thanks, the first example worked great! I haven't seen the GetMod instruction before. I think the second would use too much CPU time.

Matt
Matt B
#4
Quote:I think the second would use too much CPU time.

No. GetMessage waits until a message arrives and does not use much CPU time. RegisterHotKey is preferred method of implementing triggers in exe because does not need hooks.


Forum Jump:


Users browsing this thread: 1 Guest(s)