Custom hotkey even with unfocused form - vb.net

I am having a bit problems trying this. I must admit that I am still novice programming. Well, I managed for do this in this way (VB.NET):
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If My.Computer.Keyboard.CtrlKeyDown Then
MORE IRRELEVANT CODE HERE
End If
End Sub
But with this way, even if it work, it dont let me customice the key shortcut (only Control, shift and others).
I did this too for try differents things:
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = GlobalVariables.own_key Then
MORE IRRELEVANT CODE HERE
End If
End Sub
I give value to GlobalVariables.own_key from other button. This work perfectly, but only if program have the focus.
So... With the first code program work even if it haven't the focus but only with few keys... And with the second it let me use any key, but don't work if it haven't the focus.
I tryed understand the "keyboard hook" but I must admit that I didn't understad it and couldn't manage for work any of them.
Using VB.net 2012.
Really thanks so much for your help

It may not be an answer you like but it is the answer. In .NET, you cannot get notification of keys when your application does not have focus and you cannot get mouse events outside your applications windows. If you looked into the "Keyboard Hook", you should have read that little important fact regarding VB.
Global hooks are not supported in the .NET Framework

Related

How Can i disable all windows shortcut keys in vb.net?

I want to disable all the windows shortcut keys When my application runs,Please tell me How We can do that in vb.net.Please check my code below.
Public Class Form2
Private Sub Form2_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.Modifiers = Keys.Alt And e.KeyCode = Keys.F4 Then
e.Handled = True
End If
End Sub
End Class
You can disable and enable CTRL+ALT+DEL on demand (at least, you could. I haven't tried this in Windows 7). Take a look at the link below
SystemParametersInfo Function
http://msdn.microsoft.com/en-us/library/ms724947(v=vs.85).aspx
I can see why some people are hesitant to answer this question (and that's why I'm hesitant to post usable lines of code); but I do believe there are legit ways to use this (and clearly, Microsoft agrees because they expose this functionality through their APIs).
I have seen this done in professional/commercial software.
EDIT: I don't know whether or not this approach will disable the other keyboard short-cuts; but it should work for CTRL+ALT+DEL

How to detect a collision in a Windows Store apps?

This is my first question on Stack Overflow's possible that I'll make mistakes. (and I use a internet translator)
I do not know how to detect collision in Windows Store apps. On Windows Forms it looks like this:
If Player.Bounds.IntersectsWith (Enemy1.Bounds) Then
'do something
End If
Please give me function that returns a boolean. Thank you for all the answers.
You can give me c# code i will convert it!
This is just a function with a boolean value as result. You can try this with two simple controls, with buttons for example.
You can create a new project, add two buttons and put them away, then launch the window app, then overlap them and relaunch the app.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Button1.Bounds.IntersectsWith(Button2.Bounds) Then 'this return true/false
MsgBox("Collision detected")
End If
end sub

How do I disable all exiting in Visual Basic

I'm writing an examination piece of software for my workplace and would like to know how I can trap and cancel key-presses such as:
ALT+F4
WIN+TAB
ALT+TAB
WIN
CTRL+ALT+DEL
I'm aware CTRL+ALT+DEL may not be possible, but if any of this is it'll be a step in the right direction!
Ideally I want to prevent the action, and then open a new form I've created saying 'Unauthorised keypress'
as #SQLHound link relates... us the FormClosing event to handle what happens when a user attempts to close. But if you want to block a boot attempt, then #Plutonix suggestion may help. Something along these lines...
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Dim splashScreen as New Form
splashScreen.OpenDialog
e.Cancel=True
End Sub

(VB.NET) Scroll with mouse wheel

This question might seems stupid, but it really annoys me. :p
I use TabPages, where I activated AutoScroll, so when the content doesn't fit a TabPage, a scrollbar appears.
But I would like to scroll when I use my mouse wheel, which is far easiest than clicking on the scrollbar.
Does I have to write something in the form Loader?
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Do you have any ideas?
Thanks !
Well, I found what I was searching for, I post it in case somebody encounter the same problem as me.
So in fact, you need to make the tabs "active" to scroll. I personnally use this code hich is a bit tricky but works well :
Private Sub TAB_MouseClick(sender As Object, e As MouseEventArgs) Handles TAB.MouseClick
Me.ActiveControl = Me.TAB.SelectedTab
End Sub
Where TAB is my TabControl
Thanks for your help guys

Windows button appearance in a VB 2008 application

I am creating a Win32-application in Visual Basic 2008. I would like to have a button in the form, with custom color (BackColor), on MouseEnter event. This works fine, but as you can see below, this custom color doesn't cover the whole area of the button. The button border remains as standard (Windows 7). Can I somehow have this color for the whole button? I don't want to use Flat button style, I prefer this Standard style, which has the normal Windows look.
What I typically do is this I first gather two buttons that look similar, such as this Pic A and B.
Then I will put in those two picture into my Resources.
After I begin coding the function such as the Example I have made down below.
Now their are two ways of going about this. There is a hover option as seen below:
Private Sub PictureBox1_MouseHover(sender As Object, e As EventArgs) Handles PictureBox1.MouseHover
PictureBox1.Image = My.Resources.Button1
End Sub
or there is this option which has way better response times when moving your mouse:
Private Sub PictureBox1_MouseEnter(sender As Object, e As EventArgs) Handles PictureBox1.MouseEnter
PictureBox1.Image = My.Resources.Button1
End Sub
Then you need this to set things back to normal:
Private Sub PictureBox1_MouseLeave(sender As Object, e As EventArgs) Handles PictureBox1.MouseLeave
PictureBox1.Image = My.Resources.Button
End Sub
Real simple code but in a realistics thats all you need! I typically hate the buttons! I find myself messing with the button look more then I actually code, really simple to just go to Photoshop and make a easy button that looks good!
I read your Question don't worry but to be honest that style button looks old fashion the buttons I made are more up to date and Modern!