Archive for the ‘Windows’ Category

23
giu

Hello!

if you like linux or mac os, you should also like the windows dragging cool trick right?

In linux you can drag windows anywhere by pressing ALT+CLICK… I’m not sure, but it should be the same thing in OS X.




Googling around… I found an interesting article in howtogeek.com that explains how to do that in Windows OS!!

The original script is here:
http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm





And this is the howtogeek.com revisited script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Alt & LButton::
CoordMode, Mouse
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0
    SetTimer, EWD_WatchMouse, 10
return

EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U
{
    SetTimer, EWD_WatchMouse, off
    return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D
{
    SetTimer, EWD_WatchMouse, off
    WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
    return
}
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX
EWD_MouseStartY := EWD_MouseY
return

Oh, you want the complete package?

Ok ok… click here, extract it and put it in Autorun of your Winz.

If you want to write and compile you personalized version, I have coded a C# version, easy to use!

First of all, include Win32API in your code. This library is needed to send events to external windows.

1
2
3
4
5
6
    [DllImport( "user32.dll", CharSet = CharSet.Auto, SetLastError = false )]
    static extern IntPtr SendMessage( int hWnd, uint Msg, int wParam, int lParam );
    [DllImportAttribute( "user32.dll", CharSet = CharSet.Auto, SetLastError = false )]
    public static extern bool ReleaseCapture();
    [DllImport( "user32.dll" )]
    static extern int GetForegroundWindow();

After that, set a timer and call GetForegroundWindow() just like this:

1
     int handle = GetForegroundWindow();

Now, create the KeyHook listener class:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  public class KeyPressEventArgs : EventArgs
  {
    public KeyPressEventArgs( Keys ModifierKeys, int KeyCode )
    {
      this.ModifierKeys = ModifierKeys;
      this.KeyCode = KeyCode;
    }
    public readonly Keys ModifierKeys;
    public readonly int KeyCode;
  }

  public class KeyLoggerListener
  {
    public delegate void KeyPressHandler( object inputListener, KeyPressEventArgs KeyPressInfo );
    public event KeyPressHandler OnKeyPress;

    [DllImport( "user32.dll" )]
    public static extern int GetAsyncKeyState( long vKey );

    public void Run()
    {
      Thread t = new Thread( new ThreadStart( Listener ) );
      t.IsBackground = true;
      t.Start();
    }

    private void Listener()
    {
      while ( true )
      {
        Thread.Sleep( 10 );
        int i = 0;
        for ( i = 1; i < Byte.MaxValue; i++ )
        {
          if ( GetAsyncKeyState( i ) == Int16.MinValue + 1 )
          {
            KeyPressEventArgs KeyPressInfo = new KeyPressEventArgs( Control.ModifierKeys, i );
            if ( OnKeyPress != null )
            {
              OnKeyPress( this, KeyPressInfo );
            }
          }
        }
      }
    }
  }

Ok. Now, run it on Form_Load():

1
2
3
      KeyLoggerListener keylogger = new KeyLoggerListener();
      keylogger.OnKeyPress += new KeyLogger.KeyLoggerListener.KeyPressHandler( keylogger_OnKeyPress );
      keylogger.Run();

and create OkKeyPress event:

1
2
3
4
5
6
7
8
9
10
11
12
13
    private void keylogger_OnKeyPress( object inputListener, KeyPressEventArgs KeyPressInfo )
    {
      char digit = Convert.ToChar( KeyPressInfo.KeyCode );
      switch ( KeyPressInfo.ModifierKeys )
      {
        case Keys.Alt:
          ReleaseCapture();
          SendMessage( handle, 0xa1, 0x2, 0 );
          break;
        default:
          break;
      }
    }

It’s all!

When the ALT key is detected, the program will launch a SendMessage( handle, 0xa1, 0×2, 0 ) passing the control (handle) of the foreground window and… you can move it!

Oh, by the way, you can also move an opened Windows’ Start Menu!
You don’t believe me? Watch this!!!

Start menu drag

happy summer.

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , , ,

Switch to our mobile site