Hi Marc,
I spent several hours researching on how to disable keyboard repeat feature
and got it finally.
In fact, we can disable keyboard repeat feature through the Control Panel.
In detail, open the Control Panel,
if you're using Windows XP, double click the 'Accessibility Options' item.
In the Accessibility Options window, switch to the 'Keyboard' tab and
select the checkbox before the 'Use FilterKeys' option;
if you're using Windows Vista, double click the 'Ease of Access Center'
item and then click the 'Make the keyboard easier to use' link. In the
window opened, select the checkbox before the 'Turn on Filter Keys' option.
To turn on the Filter Keys feature programmatically, we can make use of the
SystemParametersInfo function. You can get the current value of the Filter
Keys setting by passing the SPI_GETFILTERKEYS parameter to the
SystemParametersInfo function when your application is run and set a new
value to this setting by passing the SPI_SETFILTERKEYS parameter to this
function. Remember to restore the original Filter Keys setting when the
application exits.
The following is a sample.
using System.Runtime.InteropServices;
public partial class Form1 : Form
{
int SPI_GETFILTERKEYS = 0x32;
int SPI_SETFILTERKEYS = 0x33;
int FKF_FILTERKEYSON = 1;
[DllImport("user32.dll")]
static extern bool SystemParametersInfo(int uiAction, int uiParam,
ref FilterKeys pvParam, uint fwinIni);
public struct FilterKeys
{
public UInt16 cbSize;
public int dwFlags;
public int iWaitMSec;
public int iDelayMSec;
public int iRepeatMSec;
public int iBounceMSec;
}
FilterKeys oldfilterkeys = new FilterKeys();
private void Form1_Load(object sender, EventArgs e)
{
oldfilterkeys.cbSize =
(UInt16)Marshal.SizeOf(typeof(FilterKeys));
bool result = SystemParametersInfo(SPI_GETFILTERKEYS,
Marshal.SizeOf(typeof(FilterKeys)), ref oldfilterkeys, 0);
FilterKeys newfilterkeys = oldfilterkeys;
newfilterkeys.dwFlags |= FKF_FILTERKEYSON;
newfilterkeys.iWaitMSec = 0;
newfilterkeys.iBounceMSec = 0;
newfilterkeys.iDelayMSec = 0;
newfilterkeys.iDelayMSec = 0;
// turn on the FilterKeys feature to disable keyboard
repeat
result = SystemParametersInfo(SPI_SETFILTERKEYS,
Marshal.SizeOf(typeof(FilterKeys)), ref newfilterkeys, 0);
}
void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
// restore the original Filter Keys setting
SystemParametersInfo(SPI_SETFILTERKEYS,
Marshal.SizeOf(typeof(FilterKeys)), ref oldfilterkeys, 0);
}
}
Hope this helps.
If you have any question, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.