By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,515 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,515 IT Pros & Developers. It's quick & easy.

Let arrow keys work on WebBrowser Control & catch Esc, F11, & F5 (Fullscreen/Refresh)

DTeCH
P: 23
Hello all :)


A strange feature of the MS WebBrowser Control showed it's head, & I tried figuring it out on my own, but it's stressful enough already without me having to go another week trying to make it work.


My problem is, I made a Win Forms app that loads a site's Flash game into it (many servers, & all live players). Now, when I load it up, it works fine... except it's not playable because the arrow keys are REQUIRED, but not working, & no matter how many times you press them, NOTHING happens in the game.

I have the following to catch the Esc, F11, & F5 keys:

Expand|Select|Wrap|Line Numbers
  1.     Private Sub AxWebBrowser1_PreviewKeyDown(sender As Object, e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles AxWebBrowser1.PreviewKeyDown
  2.         F11_Pressed = True
  3.  
  4.         'Arrow Keys (Up, Down, Left, & Right)
  5.         If (e.KeyCode = 37 Or e.KeyCode = 38 Or e.KeyCode = 39 Or e.KeyCode = 40) = True Then Exit Sub
  6.         Try
  7.             'F11, or Esc key (Exit FullScreen)
  8.             If Me.WindowState = FormWindowState.Maximized And (e.KeyCode = 122 Or e.KeyCode = 27) Then 
  9.  
  10.                 Me.WindowState = FormWindowState.Normal
  11.                 Me.Width = Me_Width
  12.                 Me.Height = Me_Height
  13.                 Me.ControlBox = True
  14.                 StatusStrip1.Visible = True
  15.                 Me.FormBorderStyle = 4
  16.                 MenuStrip1.Visible = True
  17.                 Me.CenterToScreen()
  18.  
  19.             'F11 key (FullScreen)
  20.             ElseIf Me.WindowState = FormWindowState.Normal And e.KeyCode = 122 Then
  21.  
  22.                 Me_Width = Me.Width
  23.                 Me_Height = Me.Height
  24.                 Me.WindowState = FormWindowState.Maximized
  25.                 Me.ControlBox = False
  26.                 StatusStrip1.Visible = False
  27.                 Me.FormBorderStyle = 0
  28.                 MenuStrip1.Visible = False
  29.  
  30.             'F5 key (Refresh)
  31.             ElseIf e.KeyCode = 116 Then
  32.  
  33.                 Application.DoEvents()
  34.                 AxWebBrowser1.Refresh()
  35.  
  36.             Else
  37.  
  38.             End If
  39.         Catch ex As Exception
  40.  
  41.         End Try
  42.     End Sub
  43.  
  44.  
They work as expected, but the Arrow keys are not being received/handled by the WebBrowser control... although it does send them in the PreviewKeyDown event. The WebBrowser control is just ignoring their actions, yet everything else works just fine.


I DO NOT want to mess with the DOM of the page (don't see why we even need to :)), or other things because that WILL get the user banned.




UPDATE:

I figured it out guys.

I changed the above code from:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         'Arrow Keys (Up, Down, Left, & Right)
  3.         If (e.KeyCode = 37 Or e.KeyCode = 38 Or e.KeyCode = 39 Or e.KeyCode = 40) = True Then Exit Sub
  4.  
  5.  
To:
Expand|Select|Wrap|Line Numbers
  1.  
  2.         'Arrow Keys (Up, Down, Left, & Right)
  3.         If (e.KeyCode = 37 Or e.KeyCode = 38 Or e.KeyCode = 39 Or e.KeyCode = 40) = True Then
  4.             e.IsInputKey = True
  5.             Exit Sub
  6.         End If
  7.  
  8.  
It did the trick :)
Jul 15 '12 #1

✓ answered by DTeCH

SOLVED :)

I love this place! lol

Share this Question
Share on Google+
1 Reply


DTeCH
P: 23
SOLVED :)

I love this place! lol
Jul 15 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.