Advertisement
metalx1000

Display Webpage Form and close when mouse moves

Jul 7th, 2014
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. Basic Web Browser in PowerShell
  3. that closes when mouse is moved
  4. you need to start power shell like this:
  5. PowerShell -ExecutionPolicy Bypass -STA
  6. #>
  7.  
  8. $URL = "http://filmsbykris.com"
  9.  
  10. [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
  11. [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
  12.  
  13. $oY = ([System.Windows.Forms.Cursor]::Position.Y )#original Mouse Y
  14. $oX = ([System.Windows.Forms.Cursor]::Position.X )#original Mouse X
  15.  
  16. function watch_mouse(){
  17.  
  18.     $mY = ([System.Windows.Forms.Cursor]::Position.Y )#Mouse Y
  19.     $mX = ([System.Windows.Forms.Cursor]::Position.X )#Mouse X
  20.     Write-Host $mX,$mY    
  21.    
  22.     #if mouse is moved
  23.     if($oX -ne $mX)
  24.     {
  25.        Write-Host "Mouse Moved on X!"
  26.        $Form.close()   
  27.     }
  28.          
  29. }
  30.  
  31. function GUI(){
  32.    
  33.     $Form = New-Object System.Windows.Forms.Form
  34.     $Form.FormBorderStyle = "None"
  35.     $Form.Text = "www.FilmsByKris.com"
  36.     $Form.Size = New-Object System.Drawing.Size(800,600)
  37.     $Form.StartPosition = "CenterScreen"
  38.    
  39.     #$Form.AutoSize = $True
  40.     #$Form.AutoSizeMode = "GrowAndShrink"
  41.    
  42.    
  43.     # Main Browser
  44.     $webBrowser = New-Object System.Windows.Forms.WebBrowser
  45.     $webBrowser.IsWebBrowserContextMenuEnabled = $true
  46.     $webBrowser.ScrollBarsEnabled = $false
  47.     $webBrowser.URL = $URL
  48.     $webBrowser.Width = 800
  49.     $webBrowser.Height = 600
  50.     $webBrowser.Location = "0, 0"
  51.     $webBrowser.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor
  52.         [System.Windows.Forms.AnchorStyles]::Right -bor
  53.         [System.Windows.Forms.AnchorStyles]::Top -bor
  54.         [System.Windows.Forms.AnchorStyles]::Left
  55.     $Form.Controls.Add($webBrowser)
  56.    
  57.     # Display Form
  58.     [void] $Form.ShowDialog()
  59. }
  60.            
  61. $timer = New-Object System.Windows.Forms.Timer
  62. $timer.Interval = 1000
  63.  
  64. $timer.add_Tick({watch_mouse})
  65.  
  66. $timer.Enabled = $true
  67. $timer.Start()
  68.  
  69. GUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement