4

I want to use AHK to simulate Ctrl + Alt + break.

The below code does nothing. I have also pasted the key history with first using the Num - and then actually pressing the set of trio keys. The AHK key doesn't work while the actual pressing of key works. The codes generated by both appear to be same to me except that Break has d & u with AHK. But that shouldn't matter. I also introduced the delay but that also doesn't work.

SetKeyDelay, 2,2
NumpadSub::
send {LCtrl Down}{LAlt Down}{vk03sc146}{LCtrl Up}{LAlt Up}
return  

I also tried with {CtrlBreak} and the below with no success in Win XP remote desktop. send !^{vk03sc146} This code works find in my win 7. However I need to remote in to the Win XP. Help please.

6D  04A     d   1.33    Num -           
A2  01D i   d   0.00    Ctrl            
A4  038 i   d   0.02    Alt             
03  146 i   d   0.02    Break           
03  146 i   u   0.02    Break           
A2  01D i   u   0.02    Ctrl            
A4  038 i   u   0.02    Alt             
6D  04A     u   0.16    Num -           
74  03F     d   1.00    F5              
74  03F     u   0.09    F5              
74  03F     d   2.02    F5              
74  03F     u   0.13    F5              
74  03F     d   0.19    F5              
74  03F     u   0.11    F5              
A2  01D     d   1.31    Ctrl            
A4  038     d   0.00    Alt             
03  146     u   0.39    Break           
A2  01D     u   0.06    Ctrl            
A4  038     u   0.03    Alt             
74  03F     d   3.08    F5       
suman upadhya
  • 41
  • 1
  • 2
  • A few questions: Have you tried {Break} instead of the Scan code? Is this your XP or Win7 scan code list (or is there no difference)? How do you launch this script on the remote machine? Do you use Dropbox where you change a script, which is automatically checked/executed by AutoHotKey to create the remote connection? – Robert Ilbrink Jan 30 '13 at 06:25
  • The scan code list I just trA2 01D i d 0.00 Ctrl A4 038 i d 0.02 Alt 13 000 i d 0.02 Pause 13 000 i u 0.02 Pause A2 01D i u 0.02 Ctrl A4 038 i u 0.02 Alt – suman upadhya Jan 30 '13 at 18:23
  • The scan code list is from Win XP. I just tried with {Break} and I got the following scan code list. A2 01D i d 0.00 Ctrl A4 038 i d 0.02 Alt 13 000 i d 0.02 Pause 13 000 i u 0.02 Pause A2 01D i u 0.02 Ctrl A4 038 i u 0.02 Alt This script is installed in the remote machine. I don't use AHK to create the remote connection but I do have another AHK running on the remote machine. While the code works from win 7 to toggle to full screen. I can't understand why I am unable to toggle back from full screen. – suman upadhya Jan 30 '13 at 18:39

3 Answers3

5

It is possible to capture the CapsLock key from AHK even if it was started before RDP, it is the ONLY key that RDP passes on to other keyboard hooks.

This can be done on the local machine. When you do it on the local machine, and NOT on the remote machine, you can use AHK to obtain the window id of MSTSC, and pass a restore command to the window (no sending of keys, which is terribly unreliable)

;Get MSTSC window (this may have to be "ahk_class TSSHELLWND" for systems other than Win7)
If WinActive("ahk_class TscShellContainerClass") {
    WinGet, active_id, ID, A
    PostMessage, 0x112, 0xF120,,, ahk_id %active_id%   ; 0x112 = WM_SYSCOMMAND, 0xF120 = SC_RESTORE
}

The above command will break MSTSC from fullscreen.

A full example of this can be seen here (http://code.ecomerc.com/Articles/RotateCube/), where it is used to break MSTSC from fullscreen and rotate the cube function of Dexpot (a 3d window manager)

Peter
  • 745
  • 6
  • 17
  • I tried the code posted by @Peter with: `NumpadMult:: If WinActive("ahk_class TscShellContainerClass") { WinGet, active_id, ID, A PostMessage, 0x112, 0xF120,,, ahk_id %active_id% ; 0x112 = WM_SYSCOMMAND, 0xF120 = SC_RESTORE }` however the key history on my local shows following and nothing happens: FF 000 a d 3.37 not found wrkstn09.local - Remote Desktop Connection FF 000 a u 0.00 not found This is on Win 7 and I checked the Remote desktop class id and it is the same as given by peter. Why is it still not working? – suman upadhya Feb 18 '13 at 20:24
  • Only the CapsLock key will be passed on to AHK. It seems you are trying to capture on the Multiplicator on the Numpad. You need to use: `^Capslock::` (Which is Ctrl+CapsLock) – Peter Jun 11 '13 at 08:54
  • Thank you! This has helped me solve the issue of sending !+{Break} to the MSTSC window. Even though MS still has the restriction of blocking AHK of sending certain system-related keys (whether incidentally or purposefully). – Ahmed Sep 02 '15 at 06:51
1

All credits to Peter's answer above, which is the only working solution so far after a hour search. I slightly modified it to make it only slightly more complete.

This AHK script allows using alt + capslock to exit full screen mode and then when the remote desktop window is selected, press the alt + capslock again to restore full screen. Start the AHK script on the host machine.

;Get MSTSC window (this may have to be "ahk_class TSSHELLWND" for systems other than Win7)
!Capslock::
T := !T
If WinActive("ahk_class TscShellContainerClass") {
    WinGet, active_id, ID, A
    if T
        PostMessage, 0x112, 0xF120,,, ahk_id %active_id%   ; 0x112 = WM_SYSCOMMAND, 0xF120 = SC_RESTORE
    else
        PostMessage, 0x112, 0xF030,,, ahk_id %active_id%   ; 0x112 = WM_SYSCOMMAND, 0xF030 = SC_MAXIMIZE
}
return
0

If the RDP client's keyboard hook is activated, then no auhotkey hotkeys will work unless the script was started after the RDP client was.

Here is a better way to write that line of code; ^!Break

Michael
  • 1,263
  • 1
  • 12
  • 28
  • On my local RDP client (win 7) with remote (win xp) the code ^!Break doesn't work. !{ctrlbreak} also doesn't work. Only the below code works : NumpadSub:: send {LCtrl Down}{LAlt Down}{vk03sc146}{LCtrl Up}{LAlt Up} return ' However this only works to take the RDP window to full screen If the RDP window is full screen then it doesn't work (key scan of win 7) when using any code including that given by @peter FF 000 a d 16.38 not found wrkstn09.tritonmarine.local - Remote Desktop Connection FF 000 a u 0.00 not found I removed all scripts from the win xp. – suman upadhya Feb 20 '13 at 19:16
  • Also as mentioned in the help I am leaving 2 spaces for line
    however it is not working here in comment. I left 2 spaces before this line.
    – suman upadhya Feb 21 '13 at 00:34
  • Regarding suggestion of Person93, I started the script after the RDP client was activated. Running all the code posted here including the code by @Peter doesn't restore the window. I get the key history on my win 7 computer FF 000 a d 16.38 not found wrkstn09.local - Remote Desktop Connection FF 000 a u 0.00 not found. However I can see that the class is correct because the code 'If WinActive("ahk_class TscShellContainerClass") { send {LCtrl Down}{LAlt Down}{vk03sc146}{LCtrl Up}{LAlt Up} }' works to make the RDP screen full screen. – suman upadhya Feb 22 '13 at 18:35