How Prince Harry and Meghan Markle have surrounded Prince Archie and Princess Lilibet with their 'chosen' Californian family - after rejecting the royals
Chappell Roan accused of pushing her assistant in red carpet viral clip
Amazon Launches First Kuiper Internet Satellites
Read more of this story at Slashdot.
Stacey Solomon shares realisation after watching explosive rows with Joe Swash back on show
The BBC 'untouchables': Broadcaster blasted in damning report looking into failings and stars with 'poor behaviour'
You wouldn't steal a... font? Famous anti-piracy campaign from the early 2000s 'uses pirated typeface'
Swiss boffins admit to secretly posting AI-penned posts to Reddit in the name of science
Researchers from the University of Zurich have admitted to secretly posting AI-generated material to popular Subreddit r/changemyview in the name of science.…
Prince William and Kate Middleton return to Isle of Mull on their wedding anniversary - 20 years after they first visited beautiful Scottish island as university students in love
CodeSOD: The Wrong Kind of Character
Today's code, at first, just looks like using literals instead of constants. Austin sends us this C#, from an older Windows Forms application:
if (e.KeyChar == (char)4) { // is it a ^D? e.Handled = true; DoStuff(); } else if (e.KeyChar == (char)7) { // is it a ^g? e.Handled = true; DoOtherStuff(); } else if (e.KeyChar == (char)Keys.Home) { e.Handled = true; SpecialGoToStart(); } else if (e.KeyChar == (char)Keys.End) { e.Handled = true; SpecialGoToEnd(); }Austin discovered this code when looking for a bug where some keyboard shortcuts didn't work. He made some incorrect assumptions about the code- first, that they were checking for a KeyDown or KeyUp event, a pretty normal way to check for keyboard shortcuts. Under that assumption, a developer would compare the KeyEventArgs.KeyCode property against an enum- something like e.KeyCode == Keys.D && Keys.Control, for a CTRL+D. That's clearly not what's happening here.
No, here, they used the KeyPressEvent, which is meant to represent the act of typing. That gives you a KeyPressEventArgs with a KeyChar property- because again, it's meant to represent typing text not keyboard shortcuts. They used the wrong event type, as it won't tell them about modifier keys in use, or gracefully handle the home or end keys. KeyChar is the ASCII character code of the key press: which, in this case, CTRL+D is the "end of transmit" character in ASCII (4), and CTRL+G is the goddamn bell character (7). So those two branches work.
But home and end don't have ASCII code points. They're not characters that show up in text. They get key codes, which represent the physical key pressed, not the character of text. So (char)Keys.Home isn't really a meaningful operation. But the enum is still a numeric value, so you can still turn it into a character- it just turns into a character that emphatically isn't the home key. It's the "$". And Keys.End turns into a "#".
It wasn't very much work for Austin to move the event handler to the correct event type, and switch to using KeyCodes, which were both more correct and more readable.
School bans pupils from wearing JUMPERS until November and sends scathing letter telling parents to stop encouraging their children to break the rules
Car Subscription Features Raise Your Risk of Government Surveillance, Police Records Show
Read more of this story at Slashdot.
Amazon’s first 27 Kuiper broadband sats make it into orbit on an Atlas V
Amazon’s first attempt to hoist production versions of its Project Kuiper broadband-beaming satellites appears to have succeeded.…
Canada election results: Mark Carney's Liberal Party projected to win as Pierre Poilievre crashes in poll
CHRISTOPHER STEVENS reviews The Honesty Box on E4: To be honest, the lie detector twist's wasted on this third-rate First Dates
Naomi Watts' child Kai, 16, poses for a fashion shoot... after dad Liev Schreiber raved about his 'nepo' kid
Essex wedding venue celebrates 30 years of weddings with search for 'first couples'
The hardest primary schools in Essex to get into ranked from highest to lowest
Bling queen Kim Kardashian to face off against 'Grandpa Gang' in court
Open source text editor poisoned with malware to target Uyghur users
Researchers at Canada’s Citizen Lab have spotted a phishing campaign and supply chain attack directed at Uyghur people living outside China, and suggest it’s an example of Beijing’s attempts to target the ethnic minority group.…