473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

KeyPress Event & MouseDown event

I'm writing a program that is designed for quick navigation using
specific buttons on the keyboard. In doing this, I have added a
KeyPress event for every control on the form to intercept the key
pressed and pass it to a standard subroutine that identifies what
action should be taken.

Unfortunately, I have a web-browser contol on the form and the
webbrowser does not include a KeyPress event.

I need some way to intercept keypress and mousedown events for the
webbrowser - my thought was to put a control that has these events on
top of the webbrowser, but I have been unable to find a control that
can be transparent while also sitting on top of a webbrowser - the
imagebox control will be transparent, but for some reason it always
falls behind the webbrowser even when I force it to the Front.

my second thought is to trap key press and mouse click events from
within the html pages I am showing in the webbrowser and then passing
them along to vb - but I don't have the slightest clue how to do that,
or even if it can be done.

Does anyone have any ideas on a soltion to this problem?

any help would be appreciated.

thanks.

Trevor Fairchild
Jul 17 '05 #1
12 24138
On 2 Feb 2004 08:33:48 -0800, MR*******@e-crime.on.ca (Trevor
Fairchild) wrote:

Have you tried Form.KeyPreview ?
Jul 17 '05 #2
Actually I'd never even heard of KeyPreview. It makes my code a lot
more compact, but unfortunately, after some testing, it does not
affect keypress events when the webbrowser is in focus.

For the moment, I have trapped the Got Focus event of the webbrowser,
redirecting it to another control, but this only works if the user
left-clicks in the webbrowser; a right-click sends commands to the
webbrowser than I cannot hijack back to VB6.

I've got some VBScript that is written into the html page that
disables the drop-down menu that you'd normally get in a web page.

The only workaround I can think of is to put a msgbox command in the
VBScript function alerting the user that he/she will have to click
elsewhere in the form in order to use the hot keys again.
er*****@nowhere.com (J French) wrote in message news:<40**************@news.btclick.com>...
On 2 Feb 2004 08:33:48 -0800, MR*******@e-crime.on.ca (Trevor
Fairchild) wrote:

Have you tried Form.KeyPreview ?

Jul 17 '05 #3
On 3 Feb 2004 05:28:44 -0800, MR*******@e-crime.on.ca (Trevor
Fairchild) wrote:
Actually I'd never even heard of KeyPreview. It makes my code a lot
more compact, but unfortunately, after some testing, it does not
affect keypress events when the webbrowser is in focus.

For the moment, I have trapped the Got Focus event of the webbrowser,
redirecting it to another control, but this only works if the user
left-clicks in the webbrowser; a right-click sends commands to the
webbrowser than I cannot hijack back to VB6.

I've got some VBScript that is written into the html page that
disables the drop-down menu that you'd normally get in a web page.

The only workaround I can think of is to put a msgbox command in the
VBScript function alerting the user that he/she will have to click
elsewhere in the form in order to use the hot keys again.


That sounds horrible

I don't use the MS webbrowser control so my suggestions can only be
'theoretical'

It sounds as if you do not particularly want the Webbrowser to have
focus ... so you could grab it back using its GotFocus event
- or even a Timer

Assuming you are using Microsoft Internet Controls - WebBrowser1
- it looks as if it steals certain keys /before/ the Form gets them in
the KeyDown Event

- [F5] and Chr$(8) for a start

And annoyinly my version of that control does not have any KeyDown
event
- shifting Focus away from it in the GotFocus event is pretty brutal
- but that might be a solution

Do you really want people to click on the HTML viewer ?
- it sounds not, but I can't be sure

Form.KeyPreview should do exactly what it says on the box
Jul 17 '05 #4
The simple answer is no, I don't want anyone to bother clicking in the
webbrowser, but there's no way for me to actually prevent them from
doing this.

I have already set the WebBrowser1.GotFocus event to automatically
bounce the focus to another control that will handle the keypress
events properly. Unfortunately, this only works if the user
LEFT-clicks with the mouse. a right click sends commands to the
webbrowser itself that supercedes the GotFocus event, for some reason.

I had also thought of the timer, but am concerned about the
performance costs for such a workaround to the subject. The program
is designed for a very fast series of key-press events to cycle
through content of a database (one time trial had me going through
3,000 records in an hour), and as such I'd have to have the timer set
to a pretty high pace in order to make the re-setting of focus
unnoticed by the user - all that for a relatively unlikely, but not
impossible situation.

I have a very simple VBscript function that is hard-coded in the html
pages, that prevents users from right-clicking the html page to get
the standard IE6 options, like view source and Save Picture as, so I
can enter code in that function to inform the user he/she will have to
click somewhere else on the form to use the hot keys again, but that
is kind of hokey and not very professional.

Unforutnately, there isn't even an Enabled or Locked property for the
webbrowser.

That's why I was hoping there was some way of superimposing another
control overtop of the webbrowser - something that could be invisible
but still hijack all attempts to click on the browser.
Jul 17 '05 #5
On 3 Feb 2004 13:17:40 -0800, MR*******@e-crime.on.ca (Trevor
Fairchild) wrote:
<snip>
Unforutnately, there isn't even an Enabled or Locked property for the
webbrowser.

That's why I was hoping there was some way of superimposing another
control overtop of the webbrowser - something that could be invisible
but still hijack all attempts to click on the browser.


Hah !

I thought this might be the case

Stick the WebBrowser on a Frame
- and disable the Frame
Jul 17 '05 #6
mwahahahaha, that did it, thanks!
Jul 17 '05 #7
mwahahaha that did it, thanks!
Jul 17 '05 #8
On 3 Feb 2004 13:17:40 -0800, MRTrevorF@e-crime.on.ca (Trevor
Fairchild) wrote:
<snip>
[color=blue]
>Unforutnately, there isn't even an Enabled or Locked property for the
>webbrowser.
>
>That's why I was hoping there was some way of superimposing another
>control overtop of the webbrowser - something that could be invisible
>but still hijack all attempts to click on the browser.[/color]

Hah !

I thought this might be the case

Stick the WebBrowser on a Frame
- and disable the Frame
The problem then is that the browser won't react to key up / down, and that it's scrollbars won't work...
Mar 30 '06 #9
With VB and the IE browser control, you can use a div that is *transparent* and position absolute (adjust z-index as needed) ... either set its width and height to 0 px, place off the visible area, or its z-index to 0 behind everything else; choose which ever you prefer for initial position / state.

Next, create a function in your web page to lock out the user by adjusting the div so that it is in front of everything else (I used a div the size of my page and set its z-index to 3 -- use what works for you). Resize if needed ...

When you want to lock the page, call this lock out function from VB like this:
WebBrowser1.Document.parentWindow.execScript("SetL ock()", "JavaScript")

All left clicks now hit the div and will not affect anything behind it ... Use this html code to block right clicks:

<HTML oncontextmenu="return false;">

(tested with VB6 and IE6 ... NOTE: users can still select text)
May 31 '06 #10
Hmmm ... I found that if a text or textarea field had data in it, that the user can still click through the locking div. To get around this, you need to override the document onmouseup event and change focus to a dummy field (off page -- set it in a 0 size div, with 0 size). Use something like this:

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript><!--
function document_onmouseup()
{
return CheckLock();
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE=javascript FOR=document EVENT=onmouseup><!--
document_onmouseup();
//-->
</SCRIPT>

In CheckLock:

if (IsLocked)
{
document.getElementById("Dummy").focus();
return false;
}
else
{
return true;
}

Users can still select text, but not modify it. I still use the locking div because when the user clicks into a field, the cursor is shown briefly ... with the locking div, no field can be selected, except those that have values shown in them.
Jun 12 '06 #11
Zach
2
...or you could skip all that work, and fix the one mistake the person made in the first post.

This will work, if all you want to do is block access to everything in the page. It will work 100% of the time, and actually in any of todays browsers also.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <img src="http://sportsforum.ws/blank.gif" 
  3.  
  4. style="width:100%;height:100%;position:absolute;top:0;left:0;zIndex:99999;" 
  5.  
  6. id="fsw">
  7.  
  8.  

Done :)
Jun 25 '06 #12
Zach
2
Well, this thing is bound and determined to break up left - so obviously, put it together.

This also allows for you to easily change if the page is reachable or not




document.getElementById('fsw').style.display="none "

now the page would be reachable





document.getElementById('fsw').style.display=""

now it wouldnt
Jun 25 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Plumer | last post by:
Hello everyone, I am using MS .NET Framework 1.0 Version 1.0.3705 developing a C# client application using SQL Server on the server side. I am looking to implement drag & drop in a TreeView...
2
by: JJ | last post by:
Hi All, I need to create a MouseDown event for a picture box . Am I doing the following right? pictureBox.MouseDown += new System.WinForms.MouseEventHandler(pictureBox_MouseDown) Then
4
by: rsmith | last post by:
How can I capture the MouseDown event on a Label ? I entered thr following code and got a " cannot handle Event 'MouseDown' because they do not have the same signature." Private Sub...
4
by: Tom | last post by:
I have a VB.NET user control that I wrote - this control has three or four other controls on it (textbox, combobox, datetime picker, etc). Now, whenever the control is on a form and the user enters...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
3
by: Fia | last post by:
Hi In Visual Basic 6 I could call keypress with an integer of a choosen key. For example I could call a textbox's keypress with the number 13 (for the enter key). But now in Visual Basic .Net I...
5
by: Steve | last post by:
In VB6 I have a screen the has a text box and a datagrid If I click the datagrid, the 1st event is to validate the textbox and then the 2nd event is a datagrid mousedown event. If a get an error...
4
by: khalid galal | last post by:
Hi, i am having a problem with removing event handlers, it is when creating nested event handlers (an event handler raising another event handler) where a part of the code is private void...
2
by: svibuk | last post by:
i have a asp.net list box populated with databae data , autopostback = true wht i need is 1) when double clicked(double click event) i want it to be visible=false 2)i want to move between the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.